In [1]:
%matplotlib inline
from matplotlib import pylab as pl
import cPickle as pickle
import pandas as pd
import numpy as np
import os
import random
In [2]:
import sys
sys.path.append('..')
uncommoent the relevant pipeline in ../seizure_detection.py
and run
cd ..
./doall data
or
./doall td
./doall tt
In [3]:
FEATURES = 'gen8_medianwindow-fft-with-time-freq-corr-1-48-r400-usf-w600'
In [4]:
from common.data import CachedDataLoader
cached_data_loader = CachedDataLoader('../data-cache')
In [5]:
def read_data(target, data_type):
fname = 'data_%s_%s_%s'%(data_type,target,FEATURES)
print fname
return cached_data_loader.load(fname,None)
In [6]:
from sklearn.ensemble import RandomForestClassifier
from sklearn.cross_validation import StratifiedKFold
from sklearn.metrics import roc_auc_score
from sklearn.linear_model import LogisticRegression as LR
clf = RandomForestClassifier(n_estimators=3000, min_samples_split=1, max_depth=10,bootstrap=False,
n_jobs=-1)
In [7]:
fpout = open('../submissions/140906-predict-direct.2.2.csv','w')
print >>fpout,'clip,preictal'
In [8]:
for target in ['Dog_1', 'Dog_2', 'Dog_3', 'Dog_4', 'Dog_5', 'Patient_1', 'Patient_2']:
pdata = read_data(target, 'preictal') # positive examples
ndata = read_data(target, 'interictal') # negative examples
X = np.concatenate((pdata.X, ndata.X))
y = np.zeros(X.shape[0])
y[:pdata.X.shape[0]] = 1
# shuffle
idxs=range(len(y))
random.shuffle(idxs)
X = X[idxs,:]
y = y[idxs]
# model
clf.fit(X,y)
# predict
tdata = read_data(target, 'test') # test examples
y_proba = clf.predict_proba(tdata.X)[:,1]
# write results
for i,p in enumerate(y_proba):
print >>fpout,'%s_test_segment_%04d.mat,%.15f' % (target, i+1, p)
In [9]:
fpout.close()
In [36]: