Can not able to split the sleep edf files

If you have a question or issue with MNE-Python, please include the following info:

  • MNE-Python version: 0.22.0
  • operating system: Windows 10

Hi
I am a new user working on EEG Sleep edf data from Sleep-EDF Database Expanded.
I’m using (Sleep stage classification from polysomnography (PSG) data — MNE 0.22.0 documentation), but I’m not able to read multiple files and Fetch 50 subjects from the Physionet database and run 5-fold cross-validation leaving each time 10 subjects out in the test set. Can you provide a reference?.

what did you try (code?) and what is the error you get?

A

from sklearn.model_selection import KFold

from sklearn.model_selection import cross_val_score

from numpy import mean

from numpy import std

kf = KFold(n_splits=3,shuffle=True)

x_train,x_test,y_train,y_test=[],[],[],[]

acc_score = []

pipe = make_pipeline(FunctionTransformer(eeg_power_band, validate=False),

                 RandomForestClassifier(n_estimators=100, random_state=42))

for train, test in kf.split(epochs_train):

print(train,test)

for i,j,k in zip(epochs_train,train,test):

print(len(i.events[:]))

x_train=i[j]

y_train=i[j].events[:,2]

x_test=i[k]

y_test=i[k].events[:,2]

pipe.fit(x_train,y_train)

y_pred = pipe.predict(x_test)

 

acc = accuracy_score(y_pred , y_test)

acc_score.append(acc)

print(‘accuracy of each fold - {}’.format(acc_score))

and output:

Code link:

sorry what is the more specific question?

A

while running this code I’m getting an Accuracy is ‘1’ for each fold, Please prove solution or references

it must be a cross-validation bug. You must be using the same data for train and test…

A