Skip to content

MRG: Trimming Sleep Physionet recordings to avoid W imbalance - #8179

Merged
larsoner merged 4 commits into
mne-tools:masterfrom
hubertjb:trim-wake-physionet
Sep 1, 2020
Merged

larsoner merged 4 commits into
mne-tools:masterfrom
hubertjb:trim-wake-physionet

Conversation

@hubertjb

@hubertjb hubertjb commented Aug 31, 2020 •

Copy link
Copy Markdown
Contributor

In the example for the Sleep Physionet dataset, there is a large class imbalance in favour of wake (W). This is because the recordings in this dataset were collected over longer periods of time and thus there are long periods of awake time before and after the night. It is common practice in the literature to trim the beginning and end parts of the recordings of this dataset to reduce class imbalance (e.g., https://arxiv.org/abs/1703.04046, https://arxiv.org/abs/1610.01683, https://arxiv.org/abs/1710.00633).

Following discussion with @agramfort, this PR modifies the example to only keep the last 30 minutes before the first sleep event and the first 30 minutes after the last sleep event when building the training and testing sets.

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a final thought, I wonder if the mintime default of equalize_event_counts would get you this for free without requiring any of these manual gymnastics, and also have the benefit of taking into account events that actually get dropped (assuming you use the original events and preload=True or epochs.drop_bad)...

Comment thread tutorials/sample-datasets/plot_sleep.py Outdated
# keep last 30-min wake events before sleep and first 30-min wake events after
# sleep
sleep_stage_inds = np.where(events_train[:, 2] > 1)[0]
offset = int((30 * 60) / 30)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The units here / reasons for the given numbers are difficult to parse. The 60 makes sense because it's sec/min, the first 30 makes sense because it's min, but then the last 30 is ... ? Probably making use of some informative variable names above (possibly having to do with the time between samples?) and reusing them here could fix this problem.

Also int(x_int / y_int) is less clean than x_int // y_int

@agramfort agramfort changed the title WIP: Trimming Sleep Physionet recordings to avoid W imbalance MRG: Trimming Sleep Physionet recordings to avoid W imbalance Sep 1, 2020
@agramfort

Copy link
Copy Markdown
Member

good to go from my end.

@larsoner merge if happy

@hubertjb

hubertjb commented Sep 1, 2020

Copy link
Copy Markdown
Contributor Author

good to go from my end.

@larsoner merge if happy

Much nicer solution, thanks!

@larsoner

larsoner commented Sep 1, 2020

Copy link
Copy Markdown
Member

Precision and recall for all classes other than Wake are better on this PR. It would be nice if there were some overall metric that would go up with this PR compared to master, instead of some going up and some going down. @agramfort I'll let you add the right one someday when you're bored :)

@larsoner
larsoner merged commit dfe4195 into mne-tools:master Sep 1, 2020
larsoner added a commit to hubertjb/mne-python that referenced this pull request Sep 2, 2020
…ysionet

* upstream/master:
  ENH: Add message (mne-tools#8193)
  ENH: Allow writing BEM in H5 format (mne-tools#8191)
  ENH: Add ori on MRI slices (mne-tools#8188)
  Ricoh new files (mne-tools#8187)
  MRG: Split _timeviewer.py into multiple files (mne-tools#8181)
  ENH: Better memory efficiency (mne-tools#8185)
  MRG: Trimming Sleep Physionet recordings to avoid W imbalance (mne-tools#8179)
  MRG, BUG: Fix montage plotting, deduplication, and preload check (mne-tools#8178)
  Test PSD topomap works with NIRS epochs (mne-tools#8180)
  MRG, MAINT: Tweak CI versions (mne-tools#8174)
marsipu pushed a commit to marsipu/mne-python that referenced this pull request Oct 14, 2020
…ols#8179)

* cutting recordings to keep only 5 minutes of W before and after sleep

* changing to 30-min before and after sleep based on Supratak et al. 2017

* use annot crop

* typo

Co-authored-by: Alexandre Gramfort <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants