{
  "id": 443569,
  "title": "Onset and Wakeup AP values for Series",
  "url": "/competitions/child-mind-institute-detect-sleep-states/discussion/443569",
  "author_name": "",
  "post_date": "2023-09-27T22:00:32.874893700Z",
  "votes": 12,
  "comment_count": 8,
  "views": 0,
  "content": "<p>As others have alluded to, it looks like some series are easier to predict than other ones. For examples, using a simple non-ML edge-fitting model which has LB ~ 0.343, the series[163] 9ee455e4770d is predicted well with AP onsets = 0.647 and AP wakeups = 0.613. On the other hand, series[276] fe90110788d2 has AP onsets = 0.290 and AP wakeups = 0.236.</p>\n<p>To look at the range of AP values (my model gives) I processed all the training series and made plots of the AP values for the onsets and for the wakeups. Here are plots and histograms for them:</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F0abbce9e3bf61a0b52dd188b920b9b8b%2Fddv32_onset_APs.png?generation=1695849993068430&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F6d3eb8df260907cb6268fb464739a964%2Fddv32_wakeup_APs.png?generation=1695850009478752&amp;alt=media\" alt=\"\"></p>\n<p>Not surprisingly there are large variations between APs for the series (i.e., between subjects, their behaviors, environments, etc..) What surprised me is that the APs for onsets and the APs for wakeups for a given series are not very correlated, so it's possible to have a high onset AP but a lower wakeup AP and the other way around. This plot shows each series plotted by its onset and wakeup APs.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F46775e8bf560502074fd6f9b5caec9b6%2Fddv32_wakeup_vs_onset.png?generation=1695850025019714&amp;alt=media\" alt=\"\"></p>\n<p>These plots are for my model, I'm wondering what these plots would look like for different models 🤔</p>",
  "messages": [
    {
      "id": "2458897",
      "postDate": "09/27/2023 22:00:32",
      "content": "<p>As others have alluded to, it looks like some series are easier to predict than other ones. For examples, using a simple non-ML edge-fitting model which has LB ~ 0.343, the series[163] 9ee455e4770d is predicted well with AP onsets = 0.647 and AP wakeups = 0.613. On the other hand, series[276] fe90110788d2 has AP onsets = 0.290 and AP wakeups = 0.236.</p>\n<p>To look at the range of AP values (my model gives) I processed all the training series and made plots of the AP values for the onsets and for the wakeups. Here are plots and histograms for them:</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F0abbce9e3bf61a0b52dd188b920b9b8b%2Fddv32_onset_APs.png?generation=1695849993068430&amp;alt=media\" alt=\"\"></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F6d3eb8df260907cb6268fb464739a964%2Fddv32_wakeup_APs.png?generation=1695850009478752&amp;alt=media\" alt=\"\"></p>\n<p>Not surprisingly there are large variations between APs for the series (i.e., between subjects, their behaviors, environments, etc..) What surprised me is that the APs for onsets and the APs for wakeups for a given series are not very correlated, so it's possible to have a high onset AP but a lower wakeup AP and the other way around. This plot shows each series plotted by its onset and wakeup APs.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F46775e8bf560502074fd6f9b5caec9b6%2Fddv32_wakeup_vs_onset.png?generation=1695850025019714&amp;alt=media\" alt=\"\"></p>\n<p>These plots are for my model, I'm wondering what these plots would look like for different models 🤔</p>",
      "rawMarkdown": "As others have alluded to, it looks like some series are easier to predict than other ones. For examples, using a simple non-ML edge-fitting model which has LB ~ 0.343, the series[163] 9ee455e4770d is predicted well with AP onsets = 0.647 and AP wakeups = 0.613. On the other hand, series[276] fe90110788d2 has AP onsets = 0.290 and AP wakeups = 0.236.\n\nTo look at the range of AP values (my model gives) I processed all the training series and made plots of the AP values for the onsets and for the wakeups. Here are plots and histograms for them:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F0abbce9e3bf61a0b52dd188b920b9b8b%2Fddv32_onset_APs.png?generation=1695849993068430&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F6d3eb8df260907cb6268fb464739a964%2Fddv32_wakeup_APs.png?generation=1695850009478752&alt=media)\n\nNot surprisingly there are large variations between APs for the series (i.e., between subjects, their behaviors, environments, etc..) What surprised me is that the APs for onsets and the APs for wakeups for a given series are not very correlated, so it's possible to have a high onset AP but a lower wakeup AP and the other way around. This plot shows each series plotted by its onset and wakeup APs.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F46775e8bf560502074fd6f9b5caec9b6%2Fddv32_wakeup_vs_onset.png?generation=1695850025019714&alt=media)\n\nThese plots are for my model, I'm wondering what these plots would look like for different models 🤔",
      "votes": null
    },
    {
      "id": "2459594",
      "postDate": "09/28/2023 09:43:11",
      "content": "<p>I'm wondering is AP correlated with number of NaN nights in series.<br>\nPs: How do you deal with NaNs in train events, drop it?</p>",
      "rawMarkdown": "I'm wondering is AP correlated with number of NaN nights in series.\nPs: How do you deal with NaNs in train events, drop it?",
      "votes": null
    },
    {
      "id": "2459914",
      "postDate": "09/28/2023 13:16:09",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/dan3dewey\" target=\"_blank\">@dan3dewey</a>. Please tell me the CV of the results shown this time.</p>",
      "rawMarkdown": "Hi @dan3dewey. Please tell me the CV of the results shown this time.",
      "votes": null
    },
    {
      "id": "2461419",
      "postDate": "09/29/2023 13:49:39",
      "content": "<p>The average of the APs over all the series, 0.393, is a good value for my \"CV\" (added to plot above) since I'm not using an ML model that is trained on, or can 'memorize', the series true values. This 0.393 is a little better than the LB value of 0.343. </p>",
      "rawMarkdown": "The average of the APs over all the series, 0.393, is a good value for my \"CV\" (added to plot above) since I'm not using an ML model that is trained on, or can 'memorize', the series true values. This 0.393 is a little better than the LB value of 0.343.",
      "votes": null
    },
    {
      "id": "2461424",
      "postDate": "09/29/2023 13:52:33",
      "content": "<p><a href=\"https://www.kaggle.com/dan3dewey\" target=\"_blank\">@dan3dewey</a> Thank you because I was concerned about the correlation between CV and LB.</p>",
      "rawMarkdown": "dan3dewey Thank you because I was concerned about the correlation between CV and LB.",
      "votes": null
    },
    {
      "id": "2461476",
      "postDate": "09/29/2023 14:19:41",
      "content": "<p>Here's a plot of AP (onset,wakeup combined) vs the ratio of number of valid (non-NaN) nights to the number of labeled nights (i.e., the max of the <code>night</code> value) in each series. You can draw your own conclusions :)</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F34bbb3a26efc1910577ba2a316d8319c%2Fddv34_AP_vs_ratio.png?generation=1695996595549304&amp;alt=media\" alt=\"\"></p>\n<p>NaNs in the train events tell us that the ground truth (if we believe the raters) for that night is that there was not a valid sleeping period. I think the scoring only cares about predicted events and ground truth events, so there is no use to submit an NaN event.  But, the AP is reduced if we provide events which are not matched to ground truth, so giving onset,wakeup values for a night that is NaN in train events will just be counted as False Positives.</p>",
      "rawMarkdown": "Here's a plot of AP (onset,wakeup combined) vs the ratio of number of valid (non-NaN) nights to the number of labeled nights (i.e., the max of the `night` value) in each series. You can draw your own conclusions :)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F34bbb3a26efc1910577ba2a316d8319c%2Fddv34_AP_vs_ratio.png?generation=1695996595549304&alt=media)\n\nNaNs in the train events tell us that the ground truth (if we believe the raters) for that night is that there was not a valid sleeping period. I think the scoring only cares about predicted events and ground truth events, so there is no use to submit an NaN event.  But, the AP is reduced if we provide events which are not matched to ground truth, so giving onset,wakeup values for a night that is NaN in train events will just be counted as False Positives.",
      "votes": null
    },
    {
      "id": "2461514",
      "postDate": "09/29/2023 14:48:59",
      "content": "<p>Thanks for the plot. What am I really asking is, when we use this line <code>metric.score(solution, submission, ...)</code> to evaluate, should we drop nans from solution? We can't predict nans anyway, so excluding nans makes sense. </p>",
      "rawMarkdown": "Thanks for the plot. What am I really asking is, when we use this line `metric.score(solution, submission, ...)` to evaluate, should we drop nans from solution? We can't predict nans anyway, so excluding nans makes sense.",
      "votes": null
    },
    {
      "id": "2461860",
      "postDate": "09/29/2023 20:34:28",
      "content": "<p>Yes, I don't think there is any reason to submit an NaN -- in fact, I was getting scoring errors from my competition submissions and decided that the reason was that I was including NaNs in submission.csv .</p>",
      "rawMarkdown": "Yes, I don't think there is any reason to submit an NaN -- in fact, I was getting scoring errors from my competition submissions and decided that the reason was that I was including NaNs in submission.csv .",
      "votes": null
    },
    {
      "id": "2461873",
      "postDate": "09/29/2023 21:17:19",
      "content": "<p>P.S. Another useful visualization, besides looking at the AP values for each series, is to look at the median onset and wakeup errors for each series. Specifically something like:</p>\n<pre><code>         = np.nanmedian(predict_onsets - actual_onsets)\n         = np.nanmedian(predict_wakeups - actual_wakeups)\n</code></pre>\n<p>where the actuals are from the events file for that series and the predicted ones match (NaNs if needed) and are made the same length as the actuals. Here's the initial plot for my model:</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2Ff32d7089370cb3de727e7bf03995530c%2Fmedian_errors_before.png?generation=1696021188410468&amp;alt=media\" alt=\"\"></p>\n<p>Finding the medians of these medians (around 30 and -30 steps), I applied correction constants to the model step values to get 0 for the median of medians, see below.  My LB went from 0.343 to 0.348, so for my model it's probably more valuable for the visuals than for an LB improvement 😆</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F6743abdfff78dce6c54eed7ead63621c%2Fmedian_errors_zeroed.png?generation=1696021211676457&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "P.S. Another useful visualization, besides looking at the AP values for each series, is to look at the median onset and wakeup errors for each series. Specifically something like:\n```\n        med_err_onsets = np.nanmedian(predict_onsets - actual_onsets)\n        med_err_wakeups = np.nanmedian(predict_wakeups - actual_wakeups)\n```\nwhere the actuals are from the events file for that series and the predicted ones match (NaNs if needed) and are made the same length as the actuals. Here's the initial plot for my model:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2Ff32d7089370cb3de727e7bf03995530c%2Fmedian_errors_before.png?generation=1696021188410468&alt=media)\n\nFinding the medians of these medians (around 30 and -30 steps), I applied correction constants to the model step values to get 0 for the median of medians, see below.  My LB went from 0.343 to 0.348, so for my model it's probably more valuable for the visuals than for an LB improvement 😆\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F6743abdfff78dce6c54eed7ead63621c%2Fmedian_errors_zeroed.png?generation=1696021211676457&alt=media)",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2459594,
      "author_name": "aphysict",
      "author_url": "",
      "post_date": "09/28/2023 09:43:11",
      "content": "<p>I'm wondering is AP correlated with number of NaN nights in series.<br>\nPs: How do you deal with NaNs in train events, drop it?</p>",
      "votes": null,
      "replies": [
        {
          "id": 2461476,
          "author_name": "dan3dewey",
          "author_url": "",
          "post_date": "09/29/2023 14:19:41",
          "content": "<p>Here's a plot of AP (onset,wakeup combined) vs the ratio of number of valid (non-NaN) nights to the number of labeled nights (i.e., the max of the <code>night</code> value) in each series. You can draw your own conclusions :)</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F34bbb3a26efc1910577ba2a316d8319c%2Fddv34_AP_vs_ratio.png?generation=1695996595549304&amp;alt=media\" alt=\"\"></p>\n<p>NaNs in the train events tell us that the ground truth (if we believe the raters) for that night is that there was not a valid sleeping period. I think the scoring only cares about predicted events and ground truth events, so there is no use to submit an NaN event.  But, the AP is reduced if we provide events which are not matched to ground truth, so giving onset,wakeup values for a night that is NaN in train events will just be counted as False Positives.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 2461514,
          "author_name": "aphysict",
          "author_url": "",
          "post_date": "09/29/2023 14:48:59",
          "content": "<p>Thanks for the plot. What am I really asking is, when we use this line <code>metric.score(solution, submission, ...)</code> to evaluate, should we drop nans from solution? We can't predict nans anyway, so excluding nans makes sense. </p>",
          "votes": null,
          "replies": [
            {
              "id": 2461860,
              "author_name": "dan3dewey",
              "author_url": "",
              "post_date": "09/29/2023 20:34:28",
              "content": "<p>Yes, I don't think there is any reason to submit an NaN -- in fact, I was getting scoring errors from my competition submissions and decided that the reason was that I was including NaNs in submission.csv .</p>",
              "votes": null,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2459914,
      "author_name": "mitsuyasuhoshino",
      "author_url": "",
      "post_date": "09/28/2023 13:16:09",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/dan3dewey\" target=\"_blank\">@dan3dewey</a>. Please tell me the CV of the results shown this time.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2461419,
          "author_name": "dan3dewey",
          "author_url": "",
          "post_date": "09/29/2023 13:49:39",
          "content": "<p>The average of the APs over all the series, 0.393, is a good value for my \"CV\" (added to plot above) since I'm not using an ML model that is trained on, or can 'memorize', the series true values. This 0.393 is a little better than the LB value of 0.343. </p>",
          "votes": null,
          "replies": [
            {
              "id": 2461424,
              "author_name": "mitsuyasuhoshino",
              "author_url": "",
              "post_date": "09/29/2023 13:52:33",
              "content": "<p><a href=\"https://www.kaggle.com/dan3dewey\" target=\"_blank\">@dan3dewey</a> Thank you because I was concerned about the correlation between CV and LB.</p>",
              "votes": null,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2461873,
      "author_name": "dan3dewey",
      "author_url": "",
      "post_date": "09/29/2023 21:17:19",
      "content": "<p>P.S. Another useful visualization, besides looking at the AP values for each series, is to look at the median onset and wakeup errors for each series. Specifically something like:</p>\n<pre><code>         = np.nanmedian(predict_onsets - actual_onsets)\n         = np.nanmedian(predict_wakeups - actual_wakeups)\n</code></pre>\n<p>where the actuals are from the events file for that series and the predicted ones match (NaNs if needed) and are made the same length as the actuals. Here's the initial plot for my model:</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2Ff32d7089370cb3de727e7bf03995530c%2Fmedian_errors_before.png?generation=1696021188410468&amp;alt=media\" alt=\"\"></p>\n<p>Finding the medians of these medians (around 30 and -30 steps), I applied correction constants to the model step values to get 0 for the median of medians, see below.  My LB went from 0.343 to 0.348, so for my model it's probably more valuable for the visuals than for an LB improvement 😆</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F6743abdfff78dce6c54eed7ead63621c%2Fmedian_errors_zeroed.png?generation=1696021211676457&amp;alt=media\" alt=\"\"></p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2458897": "As others have alluded to, it looks like some series are easier to predict than other ones. For examples, using a simple non-ML edge-fitting model which has LB ~ 0.343, the series[163] 9ee455e4770d is predicted well with AP onsets = 0.647 and AP wakeups = 0.613. On the other hand, series[276] fe90110788d2 has AP onsets = 0.290 and AP wakeups = 0.236.\n\nTo look at the range of AP values (my model gives) I processed all the training series and made plots of the AP values for the onsets and for the wakeups. Here are plots and histograms for them:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F0abbce9e3bf61a0b52dd188b920b9b8b%2Fddv32_onset_APs.png?generation=1695849993068430&alt=media)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F6d3eb8df260907cb6268fb464739a964%2Fddv32_wakeup_APs.png?generation=1695850009478752&alt=media)\n\nNot surprisingly there are large variations between APs for the series (i.e., between subjects, their behaviors, environments, etc..) What surprised me is that the APs for onsets and the APs for wakeups for a given series are not very correlated, so it's possible to have a high onset AP but a lower wakeup AP and the other way around. This plot shows each series plotted by its onset and wakeup APs.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F46775e8bf560502074fd6f9b5caec9b6%2Fddv32_wakeup_vs_onset.png?generation=1695850025019714&alt=media)\n\nThese plots are for my model, I'm wondering what these plots would look like for different models 🤔",
    "2459594": "I'm wondering is AP correlated with number of NaN nights in series.\nPs: How do you deal with NaNs in train events, drop it?",
    "2459914": "Hi @dan3dewey. Please tell me the CV of the results shown this time.",
    "2461419": "The average of the APs over all the series, 0.393, is a good value for my \"CV\" (added to plot above) since I'm not using an ML model that is trained on, or can 'memorize', the series true values. This 0.393 is a little better than the LB value of 0.343.",
    "2461424": "dan3dewey Thank you because I was concerned about the correlation between CV and LB.",
    "2461476": "Here's a plot of AP (onset,wakeup combined) vs the ratio of number of valid (non-NaN) nights to the number of labeled nights (i.e., the max of the `night` value) in each series. You can draw your own conclusions :)\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F34bbb3a26efc1910577ba2a316d8319c%2Fddv34_AP_vs_ratio.png?generation=1695996595549304&alt=media)\n\nNaNs in the train events tell us that the ground truth (if we believe the raters) for that night is that there was not a valid sleeping period. I think the scoring only cares about predicted events and ground truth events, so there is no use to submit an NaN event.  But, the AP is reduced if we provide events which are not matched to ground truth, so giving onset,wakeup values for a night that is NaN in train events will just be counted as False Positives.",
    "2461514": "Thanks for the plot. What am I really asking is, when we use this line `metric.score(solution, submission, ...)` to evaluate, should we drop nans from solution? We can't predict nans anyway, so excluding nans makes sense.",
    "2461860": "Yes, I don't think there is any reason to submit an NaN -- in fact, I was getting scoring errors from my competition submissions and decided that the reason was that I was including NaNs in submission.csv .",
    "2461873": "P.S. Another useful visualization, besides looking at the AP values for each series, is to look at the median onset and wakeup errors for each series. Specifically something like:\n```\n        med_err_onsets = np.nanmedian(predict_onsets - actual_onsets)\n        med_err_wakeups = np.nanmedian(predict_wakeups - actual_wakeups)\n```\nwhere the actuals are from the events file for that series and the predicted ones match (NaNs if needed) and are made the same length as the actuals. Here's the initial plot for my model:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2Ff32d7089370cb3de727e7bf03995530c%2Fmedian_errors_before.png?generation=1696021188410468&alt=media)\n\nFinding the medians of these medians (around 30 and -30 steps), I applied correction constants to the model step values to get 0 for the median of medians, see below.  My LB went from 0.343 to 0.348, so for my model it's probably more valuable for the visuals than for an LB improvement 😆\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1496178%2F6743abdfff78dce6c54eed7ead63621c%2Fmedian_errors_zeroed.png?generation=1696021211676457&alt=media)"
  },
  "source": "meta"
}