# EEG seizure analysis with machine learning and epochs

**URL:** <https://mne.discourse.group/t/eeg-seizure-analysis-with-machine-learning-and-epochs/7908>\
**Category:** Support & Discussions\
**Tags:** eeg\
**Created:** [November 27, 2023, 11:48am UTC](https://mne.discourse.group/t/eeg-seizure-analysis-with-machine-learning-and-epochs/7908 "2023-11-27T11:48:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nico223](https://avatars.discourse-cdn.com/v4/letter/n/bc8723/32.png) [@Nico223](https://mne.discourse.group/u/Nico223)\
**Post date:** [November 27, 2023, 11:48am UTC](https://mne.discourse.group/t/eeg-seizure-analysis-with-machine-learning-and-epochs/7908/1 "2023-11-27T11:48:00Z")

</div>

Hello, thank you for letting me post my question!

I have problems understanding the Output of the prediciton of the sklearn function.

[Model training with this file:](https://1drv.ms/u/s!AnqjVVsYpLc_jKE2-wllpnWaQktSKQ?e=4gn6bD)

[Trying to load a few sample data (actually training data) to check model:](https://1drv.ms/u/s!AnqjVVsYpLc_i_kbWq-iuz3WjnlW9g?e=iCVkPX)

example output with predict

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/6/6b3f5620600e3d5bc161399d8f158aca061c21b2.png)

Anyone having an idea what exactly the 0 and 1 are telling me?

features array consists of 19 Channels with each analyse psds in 6 freqBands = 114 rows and 75 lines --epochs?!

Thanks so much in advance

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 27, 2023, 1:12pm UTC](https://mne.discourse.group/t/eeg-seizure-analysis-with-machine-learning-and-epochs/7908/2 "2023-11-27T13:12:47Z")

</div>

Hello and welcome to the forum!

It’s really difficult to tell from just looking at the code. I would guess that maybe 1 means that a seizure was detected in the respective epoch?

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![Nico223](https://avatars.discourse-cdn.com/v4/letter/n/bc8723/32.png) [@Nico223](https://mne.discourse.group/u/Nico223)\
**Post date:** [November 27, 2023, 6:00pm UTC](https://mne.discourse.group/t/eeg-seizure-analysis-with-machine-learning-and-epochs/7908/3 "2023-11-27T18:00:51Z")

</div>

Hello Richard,

Thanks! Ok i think i got it now each value corresponds to a labeled epoch. So 0 means there was detected a seizure in this specific epoch.

This leads to another question. Is there any Chance to extract the time in second from the epoch array Index?

I want to determine when exactly the seizure has been detected.

Another idea of mine, since We habe fixed epoch lengths is just to add epoch lengs until the seizure has been detected.

Just like that:

> loader = Loaded.predict(features)  
> print(loader)  
> print(len(loader))
> 
> ```
> #minDauerChecker = False
> 
> ```
> 
> # minDauerCounter = 0
> 
> ```
> for index, value in enumerate(loader):
> if value == 0: #Anfall erkannt, allerdings nur wenn mindestens 10 sekunden lang!! also in dem Fall 2s Fenster = 5*0Epochen
> #minDauerCounter += 1
> #if minDauerChecker == 2:
> SeizureEpoch = index + 1
> print(SeizureEpoch)
> seizure_present = True
> onset = SeizureEpoch*2 #wegen Epochenlänge fix
> # gibt den Beginn des Anfalls an (in Sekunden)
> break
> else: #Kein Anfall
> seizure_present = False
> #minDauerCounter = 0
> 
> ```

An opinions on that?

Thanks in Advance!

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 28, 2023, 12:16pm UTC](https://mne.discourse.group/t/eeg-seizure-analysis-with-machine-learning-and-epochs/7908/4 "2023-11-28T12:16:24Z")

</div>

> [@Nico223](#):
>
> We habe fixed epoch lengths is just to add epoch lengs until the seizure has been detected.

This sounds like a reasonable approach to me. Be careful not to accidentally be off by one epoch 😃 because in the code snippet you shared, I believe you **are** off, but I might be mistaken.

---

<div class="post-metadata">

**Author:** ![Nico223](https://avatars.discourse-cdn.com/v4/letter/n/bc8723/32.png) [@Nico223](https://mne.discourse.group/u/Nico223)\
**Post date:** [November 30, 2023, 8:56am UTC](https://mne.discourse.group/t/eeg-seizure-analysis-with-machine-learning-and-epochs/7908/5 "2023-11-30T08:56:28Z")

</div>

Thanks so much for your answer,

im investigating the counter mistke you are talking about, but cannot find one… Maybe you can clarify your thoughts?

Thanks so much!

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [November 30, 2023, 10:10am UTC](https://mne.discourse.group/t/eeg-seizure-analysis-with-machine-learning-and-epochs/7908/6 "2023-11-30T10:10:15Z")

</div>

In the code you shared above:

```python
for index, value in enumerate(loader):
    if value == 0:
        SeizureEpoch = index + 1
        onset = SeizureEpoch*2

```

For a seizure that starts in the very first epoch already (`index == 0`), you’d assume its onset is at `(index + 1) * 2 = 1 * 2 = 2` seconds – not at 0 seconds; which is clearly wrong.

Ciao,  
Richard
