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
from collections import defaultdict
In [2]:
import sys
sys.path.append('..')
Compute AUC for each target separatly
In [3]:
import scipy.io
target2metainfo = defaultdict(dict)
for target in ['Dog_1', 'Dog_2', 'Dog_3', 'Dog_4', 'Dog_5', 'Patient_1', 'Patient_2']:
print target
last_sequence = last_data_length_sec = last_Fs = last_channels = last_d_shape = None
for data_type in ['preictal', 'interictal', 'test']:
print data_type
first_sequence = last_sequence = last_data_length_sec = last_Fs = last_channels = last_d_shape = None
sequences = []
for segment in range(1,10000):
fname = '../seizure-data/%s/%s_%s_segment_%04d.mat'%(target,target,data_type,segment)
try:
data = scipy.io.loadmat(fname)
except:
break
k = '%s_segment_%d'%(data_type, segment)
data_length_sec = data[k]['data_length_sec'][0,0][0,0]
target2metainfo[target]['data_length_sec'] = data_length_sec
try:
sequence = data[k]['sequence'][0,0][0,0]
except:
sequence = 1 # test data
Fs = float(data[k]['sampling_frequency'][0,0][0,0])
target2metainfo[target]['Fs'] = Fs
channels = [t[0] for t in data[k]['channels'][0,0][0]]
target2metainfo[target]['channels'] = channels
d = data[k]['data'][0,0]
# print segment,data_length_sec,sequence,Fs,d.shape
assert len(channels) == d.shape[0]
assert int(Fs*data_length_sec + 0.5) == d.shape[1],int(Fs*data_length_sec + 0.5)
assert last_data_length_sec is None or last_data_length_sec == data_length_sec
last_data_length_sec = data_length_sec
assert last_Fs is None or last_Fs == Fs
last_Fs = Fs
assert last_channels is None or all(c1==c2 for c1,c2 in zip(last_channels, channels))
last_channels = channels
assert last_d_shape is None or last_d_shape == d.shape
last_d_shape = d.shape
if last_sequence is None:
first_sequence = sequence
elif last_sequence+1 != sequence:
sequences.append((first_sequence, last_sequence))
first_sequence = sequence
last_sequence = sequence
sequences.append((first_sequence, last_sequence))
target2metainfo[target][data_type + '_nsegments'] = segment-1
target2metainfo[target][data_type + '_sequences'] = sequences
print segment-1, len(sequences)
In [3]:
In [5]:
with open('../data-cache/140925-metainfo.pkl','wb') as fp:
pickle.dump(target2metainfo, fp, -1)
In [9]:
dict((t,len(target2metainfo[t]['channels'])) for t in target2metainfo.iterkeys())
Out[9]:
In [11]:
for target, metainfo in target2metainfo.iteritems():
pnsegments = metainfo['preictal_nsegments']
nsegments = pnsegments + metainfo['interictal_nsegments']
pnsequences = len(metainfo['preictal_sequences'])
nsequences = pnsequences + len(metainfo['interictal_sequences'])
print target,100.*pnsegments/nsegments,100.*pnsequences/nsequences
In [ ]: