{
  "id": 459636,
  "title": "1790th Place Solution - code details, attempts and insights",
  "url": "/competitions/child-mind-institute-detect-sleep-states/discussion/459636",
  "author_name": "Co_yamax",
  "post_date": "2023-12-06T04:19:57.719000",
  "votes": 9,
  "comment_count": 0,
  "views": 0,
  "content": "<p>Hello fellow Kagglers,</p>\n<p>Firstly, I would like to congratulate all the winners and participants of the recently concluded Child Mind Institute - Detect Sleep States Competition. Although my result was in the \"top 96%\", which isn't quite where I had hoped, I wanted to share my solution and the insights I gained throughout the competition. My aim is to contribute to the community and hopefully offer some insights for other newcomers.</p>\n<p><strong>Context</strong></p>\n<ul>\n<li>Business context: <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states\" target=\"_blank\">https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states</a></li>\n<li>Data context: <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/data\" target=\"_blank\">https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/data</a></li>\n</ul>\n<p><strong>Overview of the approach</strong></p>\n<ul>\n<li>Target<ul>\n<li>classification of 4-class events<ul>\n<li>Awake, Sleep (negative when submitted)</li>\n<li>Onset, Wakeup (positive when submitted)</li></ul></li></ul></li>\n<li>Features<ul>\n<li>enmo, anglez: as default</li>\n<li>shift_anglez: lagged feature varied from anglez to capture time-series data characteristics (step=1)</li>\n<li>hour_sin, hour_cos: cycled features varied from timesteps</li></ul></li>\n<li>Training method: LightGBM</li>\n<li>Validation：Hold-out<ul>\n<li>train, valid = 221, 56</li></ul></li>\n<li>Evaluation<ul>\n<li>AP (LB score: 0.004)</li></ul></li>\n</ul>\n<p><strong>Details of the submission</strong><br>\nAll parts of the code are open in the following notebooks so feel free to refer to them:<br>\n    * Dataset: <a href=\"https://www.kaggle.com/datasets/coyamax/cmi-anglezlag\" target=\"_blank\">https://www.kaggle.com/datasets/coyamax/cmi-anglezlag</a><br>\n    * Training model and validation: <a href=\"https://www.kaggle.com/code/coyamax/fork-of-cmi-train2-11?kernelSessionId=153365353\" target=\"_blank\">https://www.kaggle.com/code/coyamax/fork-of-cmi-train2-11?kernelSessionId=153365353</a><br>\n    * Inference: <a href=\"https://www.kaggle.com/code/coyamax/cmi-infer-final?kernelSessionId=153746953\" target=\"_blank\">https://www.kaggle.com/code/coyamax/cmi-infer-final?kernelSessionId=153746953</a></p>\n<p><strong>Attempts and insights</strong><br>\nLagged features: </p>\n<ul>\n<li>lagged features derived from anglez  and enmo (shift_anglez and shift_enmo, respectively) have different impacts on scores; shift_anglez leads better results than shift_enmo and both of two used together.<ul>\n<li>Only shift_anglez used: 0.004</li>\n<li>Only shift_enmo used: 0.003</li>\n<li>Both of shitf_anglez and shift_enmo used: 0.002</li></ul></li>\n<li>The result may suggest using more features derived from anglez is more effective than those from enmo if computational resources are limited.<br>\n[Feature importance of features at the same time]<br>\n￼<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2F04fc8780b328d777d9575cb0dac2543e%2Ff_imp.jpg?generation=1701835769332359&amp;alt=media\" alt=\"\"></li>\n</ul>\n<p>Post-process:</p>\n<ul>\n<li>The model predicts four labels, awake (the state of not sleeping), sleep (the state of sleeping), onset (when the state of sleeping begins), and wakeup (when the state of sleeping ends).</li>\n<li>Final submission only uses the predictions of onset and wakeup directly, by extracting the peaks of prediction scores for each series id.</li>\n<li>In the development process, I also hypothesized the predicted results of awake and sleep may be the key to predict onset and wakeup; valleys of prediction scores (near 0, in other words) of awake and sleep correspond to the steps of onset and wakeup, respectively. However, it turns out detecting score valleys of awake and sleep don’t have significant effect on predicting positive labels compared to detecting the score peaks of wakeup and onset, which ends up with LB score 0.</li>\n<li>It concludes that simple peak detection on the onset/wakeup scores performs better in my case.<br>\n[Prediction scores of awake for 3 samples of series ids]<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2F5be8559d565383751d601c4eec60dd66%2Fawake.png?generation=1701835788873540&amp;alt=media\" alt=\"\"><br>\n[Prediction scores of sleep for 3 samples of series ids]<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2Fee640d2040c9f10ea95736f2757496e0%2Fsleep.png?generation=1701835824555093&amp;alt=media\" alt=\"\"></li>\n</ul>\n<p><strong>Sources</strong></p>\n<ul>\n<li><a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/452940\" target=\"_blank\">https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/452940</a></li>\n</ul>",
  "messages": [
    {
      "id": 2550488,
      "postDate": "2023-12-06T04:19:57.720Z",
      "content": "<p>Hello fellow Kagglers,</p>\n<p>Firstly, I would like to congratulate all the winners and participants of the recently concluded Child Mind Institute - Detect Sleep States Competition. Although my result was in the \"top 96%\", which isn't quite where I had hoped, I wanted to share my solution and the insights I gained throughout the competition. My aim is to contribute to the community and hopefully offer some insights for other newcomers.</p>\n<p><strong>Context</strong></p>\n<ul>\n<li>Business context: <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states\" target=\"_blank\">https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states</a></li>\n<li>Data context: <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/data\" target=\"_blank\">https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/data</a></li>\n</ul>\n<p><strong>Overview of the approach</strong></p>\n<ul>\n<li>Target<ul>\n<li>classification of 4-class events<ul>\n<li>Awake, Sleep (negative when submitted)</li>\n<li>Onset, Wakeup (positive when submitted)</li></ul></li></ul></li>\n<li>Features<ul>\n<li>enmo, anglez: as default</li>\n<li>shift_anglez: lagged feature varied from anglez to capture time-series data characteristics (step=1)</li>\n<li>hour_sin, hour_cos: cycled features varied from timesteps</li></ul></li>\n<li>Training method: LightGBM</li>\n<li>Validation：Hold-out<ul>\n<li>train, valid = 221, 56</li></ul></li>\n<li>Evaluation<ul>\n<li>AP (LB score: 0.004)</li></ul></li>\n</ul>\n<p><strong>Details of the submission</strong><br>\nAll parts of the code are open in the following notebooks so feel free to refer to them:<br>\n    * Dataset: <a href=\"https://www.kaggle.com/datasets/coyamax/cmi-anglezlag\" target=\"_blank\">https://www.kaggle.com/datasets/coyamax/cmi-anglezlag</a><br>\n    * Training model and validation: <a href=\"https://www.kaggle.com/code/coyamax/fork-of-cmi-train2-11?kernelSessionId=153365353\" target=\"_blank\">https://www.kaggle.com/code/coyamax/fork-of-cmi-train2-11?kernelSessionId=153365353</a><br>\n    * Inference: <a href=\"https://www.kaggle.com/code/coyamax/cmi-infer-final?kernelSessionId=153746953\" target=\"_blank\">https://www.kaggle.com/code/coyamax/cmi-infer-final?kernelSessionId=153746953</a></p>\n<p><strong>Attempts and insights</strong><br>\nLagged features: </p>\n<ul>\n<li>lagged features derived from anglez  and enmo (shift_anglez and shift_enmo, respectively) have different impacts on scores; shift_anglez leads better results than shift_enmo and both of two used together.<ul>\n<li>Only shift_anglez used: 0.004</li>\n<li>Only shift_enmo used: 0.003</li>\n<li>Both of shitf_anglez and shift_enmo used: 0.002</li></ul></li>\n<li>The result may suggest using more features derived from anglez is more effective than those from enmo if computational resources are limited.<br>\n[Feature importance of features at the same time]<br>\n￼<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2F04fc8780b328d777d9575cb0dac2543e%2Ff_imp.jpg?generation=1701835769332359&amp;alt=media\" alt=\"\"></li>\n</ul>\n<p>Post-process:</p>\n<ul>\n<li>The model predicts four labels, awake (the state of not sleeping), sleep (the state of sleeping), onset (when the state of sleeping begins), and wakeup (when the state of sleeping ends).</li>\n<li>Final submission only uses the predictions of onset and wakeup directly, by extracting the peaks of prediction scores for each series id.</li>\n<li>In the development process, I also hypothesized the predicted results of awake and sleep may be the key to predict onset and wakeup; valleys of prediction scores (near 0, in other words) of awake and sleep correspond to the steps of onset and wakeup, respectively. However, it turns out detecting score valleys of awake and sleep don’t have significant effect on predicting positive labels compared to detecting the score peaks of wakeup and onset, which ends up with LB score 0.</li>\n<li>It concludes that simple peak detection on the onset/wakeup scores performs better in my case.<br>\n[Prediction scores of awake for 3 samples of series ids]<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2F5be8559d565383751d601c4eec60dd66%2Fawake.png?generation=1701835788873540&amp;alt=media\" alt=\"\"><br>\n[Prediction scores of sleep for 3 samples of series ids]<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2Fee640d2040c9f10ea95736f2757496e0%2Fsleep.png?generation=1701835824555093&amp;alt=media\" alt=\"\"></li>\n</ul>\n<p><strong>Sources</strong></p>\n<ul>\n<li><a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/452940\" target=\"_blank\">https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/452940</a></li>\n</ul>",
      "rawMarkdown": "Hello fellow Kagglers,\n\nFirstly, I would like to congratulate all the winners and participants of the recently concluded Child Mind Institute - Detect Sleep States Competition. Although my result was in the \"top 96%\", which isn't quite where I had hoped, I wanted to share my solution and the insights I gained throughout the competition. My aim is to contribute to the community and hopefully offer some insights for other newcomers.\n\n**Context**\n* Business context: https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states\n* Data context: https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/data\n\n**Overview of the approach**\n* Target\n    * classification of 4-class events\n        * Awake, Sleep (negative when submitted)\n        * Onset, Wakeup (positive when submitted)\n* Features\n    * enmo, anglez: as default\n    * shift_anglez: lagged feature varied from anglez to capture time-series data characteristics (step=1)\n    * hour_sin, hour_cos: cycled features varied from timesteps\n* Training method: LightGBM\n* Validation：Hold-out\n    * train, valid = 221, 56\n* Evaluation\n    * AP (LB score: 0.004)\n\n**Details of the submission**\nAll parts of the code are open in the following notebooks so feel free to refer to them:\n    * Dataset: https://www.kaggle.com/datasets/coyamax/cmi-anglezlag\n    * Training model and validation: https://www.kaggle.com/code/coyamax/fork-of-cmi-train2-11?kernelSessionId=153365353\n    * Inference: https://www.kaggle.com/code/coyamax/cmi-infer-final?kernelSessionId=153746953\n\n**Attempts and insights**\nLagged features: \n- lagged features derived from anglez  and enmo (shift_anglez and shift_enmo, respectively) have different impacts on scores; shift_anglez leads better results than shift_enmo and both of two used together.\n    - Only shift_anglez used: 0.004\n    - Only shift_enmo used: 0.003\n    - Both of shitf_anglez and shift_enmo used: 0.002\n- The result may suggest using more features derived from anglez is more effective than those from enmo if computational resources are limited.\n[Feature importance of features at the same time]\n￼![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2F04fc8780b328d777d9575cb0dac2543e%2Ff_imp.jpg?generation=1701835769332359&alt=media)\n\nPost-process:\n- The model predicts four labels, awake (the state of not sleeping), sleep (the state of sleeping), onset (when the state of sleeping begins), and wakeup (when the state of sleeping ends).\n- Final submission only uses the predictions of onset and wakeup directly, by extracting the peaks of prediction scores for each series id.\n- In the development process, I also hypothesized the predicted results of awake and sleep may be the key to predict onset and wakeup; valleys of prediction scores (near 0, in other words) of awake and sleep correspond to the steps of onset and wakeup, respectively. However, it turns out detecting score valleys of awake and sleep don’t have significant effect on predicting positive labels compared to detecting the score peaks of wakeup and onset, which ends up with LB score 0.\n- It concludes that simple peak detection on the onset/wakeup scores performs better in my case.\n[Prediction scores of awake for 3 samples of series ids]\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2F5be8559d565383751d601c4eec60dd66%2Fawake.png?generation=1701835788873540&alt=media)\n[Prediction scores of sleep for 3 samples of series ids]\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2Fee640d2040c9f10ea95736f2757496e0%2Fsleep.png?generation=1701835824555093&alt=media)\n\n**Sources**\n- https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/452940",
      "votes": 9
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "2550488": "Hello fellow Kagglers,\n\nFirstly, I would like to congratulate all the winners and participants of the recently concluded Child Mind Institute - Detect Sleep States Competition. Although my result was in the \"top 96%\", which isn't quite where I had hoped, I wanted to share my solution and the insights I gained throughout the competition. My aim is to contribute to the community and hopefully offer some insights for other newcomers.\n\n**Context**\n* Business context: https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states\n* Data context: https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/data\n\n**Overview of the approach**\n* Target\n    * classification of 4-class events\n        * Awake, Sleep (negative when submitted)\n        * Onset, Wakeup (positive when submitted)\n* Features\n    * enmo, anglez: as default\n    * shift_anglez: lagged feature varied from anglez to capture time-series data characteristics (step=1)\n    * hour_sin, hour_cos: cycled features varied from timesteps\n* Training method: LightGBM\n* Validation：Hold-out\n    * train, valid = 221, 56\n* Evaluation\n    * AP (LB score: 0.004)\n\n**Details of the submission**\nAll parts of the code are open in the following notebooks so feel free to refer to them:\n    * Dataset: https://www.kaggle.com/datasets/coyamax/cmi-anglezlag\n    * Training model and validation: https://www.kaggle.com/code/coyamax/fork-of-cmi-train2-11?kernelSessionId=153365353\n    * Inference: https://www.kaggle.com/code/coyamax/cmi-infer-final?kernelSessionId=153746953\n\n**Attempts and insights**\nLagged features: \n- lagged features derived from anglez  and enmo (shift_anglez and shift_enmo, respectively) have different impacts on scores; shift_anglez leads better results than shift_enmo and both of two used together.\n    - Only shift_anglez used: 0.004\n    - Only shift_enmo used: 0.003\n    - Both of shitf_anglez and shift_enmo used: 0.002\n- The result may suggest using more features derived from anglez is more effective than those from enmo if computational resources are limited.\n[Feature importance of features at the same time]\n￼![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2F04fc8780b328d777d9575cb0dac2543e%2Ff_imp.jpg?generation=1701835769332359&alt=media)\n\nPost-process:\n- The model predicts four labels, awake (the state of not sleeping), sleep (the state of sleeping), onset (when the state of sleeping begins), and wakeup (when the state of sleeping ends).\n- Final submission only uses the predictions of onset and wakeup directly, by extracting the peaks of prediction scores for each series id.\n- In the development process, I also hypothesized the predicted results of awake and sleep may be the key to predict onset and wakeup; valleys of prediction scores (near 0, in other words) of awake and sleep correspond to the steps of onset and wakeup, respectively. However, it turns out detecting score valleys of awake and sleep don’t have significant effect on predicting positive labels compared to detecting the score peaks of wakeup and onset, which ends up with LB score 0.\n- It concludes that simple peak detection on the onset/wakeup scores performs better in my case.\n[Prediction scores of awake for 3 samples of series ids]\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2F5be8559d565383751d601c4eec60dd66%2Fawake.png?generation=1701835788873540&alt=media)\n[Prediction scores of sleep for 3 samples of series ids]\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F11605610%2Fee640d2040c9f10ea95736f2757496e0%2Fsleep.png?generation=1701835824555093&alt=media)\n\n**Sources**\n- https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/452940"
  }
}