yasa icon indicating copy to clipboard operation
yasa copied to clipboard

Please help

Open Brandoncheaa opened this issue 1 year ago • 1 comments

Hello,

I am applying YASA to the sleep-edf data/sleep-edf-database-expanded-1.0.0 specifically this file, SC4001E0-PSG.edf. I am following along with notebook 14 just to understand how it produces the hypnogram file. The duration of the file states 22:04:60 (HH:MM:SS) however the hypnogram generated using this block of code below

"# Let's first create a dataframe with the predicted stages and confidence df_pred = pd.DataFrame({'Stage': y_pred, 'Confidence': confidence}) df_pred.head(6)

Now export to a CSV file

df_pred.to_csv("my_hypno.csv")"

Screenshot 2024-05-12 230313

it generates roughly the right amount of epochs however when I go to input the annotations along with the edf file in edfbrowser it leaves off a big portion without annotations. I have a feeling this could be a user error in terms of edfbrowser usage but I followed instructions at this link: https://raphaelvallat.com/yasa/build/html/faq.html. I am using this for a senior project and will be applying it to real world data we will generate from our device. I am also a little confused in how I would go about generating a confusion matrix, I'm used to generating one for simpler data but am confused on how I should go about doing it for this situation. Any help would greatly be appreciated.

Thank you for your help, Brandon

Brandoncheaa avatar May 13 '24 06:05 Brandoncheaa

Hi,

Have you solved the problem? There's clearly something off with the way that the annotations are parsed into EDFBrowser, because each discrete epoch should be 30-seconds. Based on your screenshot, it seems that the epochs are interpreted by EDFBrowser to have roughly ~1-sec duration, which is clearly wrong.

To generate a confusion matrix you need to:

  1. Get the YASA predicted sleep stages
  2. Load the reference sleep stages into a numpy array or a pandas series, with the same label mapping as YASA (e.g. 0 = Wake, 1 = N1, etc)
  3. Use scikit-learn to calculate and/or plot the confusion matrix.

Thanks Raphael

raphaelvallat avatar May 25 '24 11:05 raphaelvallat