Create Epoch lengths with events_from_annotations and predict Seizure in EEG data

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

  • MNE version: 1.6
  • operating system: Windows 11

Hello,

im coding an automatic seizure detection for EEG signals with onset prediction.
I do need help with the logic of fitting events from annotations into the corrct epochs and especially writing a function, able to predict the seizure in an unkown file.

Known are the onset and offsets in training data of sezure. Based in this annotations in raw object are created. So basically from onset to offset is annotated :“seizure” and any other timepoint is annotated:“Noseizure”

Creating events with events by annotations

#von Raw zu Epochen
    ids = {
        "seizure" :1,
        "Noseizure" :0,
    }
events, event_id = mne.events_from_annotations(rawDataPrePro, event_id=ids, 
        chunk_duration=2, verbose="warning") #Ereignisfenster 2 s
 
epochs = mne.Epochs(rawDataPrePro, events, tmin=-0.7, tmax=2.3, 
        event_id=event_id, preload = True,  verbose = "warning")#tmin und tmax also 
        den Zeitbereich um jedes Ereignis     

i do now have epochs with each 3s and every epoch has an event which tells me if this epoch is a seizure Epoch. Correct? This information is exported to an label array to use with RandomForestCLF.

When trying to predict seizures in unkown data, i have to use

 epochs=mne.make_fixed_length_epochs(rawDataPrePro,duration=3,overlap=0.7) 
         #Anpassen, ergibt sich aus der Chunk Länge und tmin und tmax für Epochen

beacause events cannot be created by annotations since there are no seizures known.

Same Feature extraction as in trainer code and analysing predict array from model, representing each epoch, 0 and 1 for seizure. Like this:

Since i know each epoch is 3s i can now multiply index number of first detected 1- and get the onset time in sec for seizure.

Problem:
Prediction perfomance and especially onset prediciton is very bad eventhough i used the same training data for verification… where is the logical mistake im making? Is there any way to create fixed epochs right away?!

Thanks so much in advance!

Nico