{
  "id": 456143,
  "title": "Releasing my findings.",
  "url": "/competitions/child-mind-institute-detect-sleep-states/discussion/456143",
  "author_name": "",
  "post_date": "2023-11-18T09:15:22.617538400Z",
  "votes": 18,
  "comment_count": 19,
  "views": 0,
  "content": "<p>Hi Guys, I am struggling with resource and time constraints, wanted to try Temporal Fusion Transformers but Still have not been able to successfully train them. If Anybody can Share a working Temporal Fusion Transformers Kaggle Notebook with offline Imports for Reference that would be a great help. Anyways! releasing <strong>2 Most Important Features in my findings</strong>: </p>\n<p><strong>1. Smoothed AngleZ Difference using Savgol Filter in Scipy.signal</strong> <br>\nwindow size 5 hr and polynomial 3 worked for me so far.<br>\n<em>pl.col(\"anglez\").diff(1).abs().alias(\"anglez_abs_diff\")</em><br>\n<em>series_df['anglez_savgolFilter_300'] = savgol_filter(series_df['anglez_abs_diff'].copy(), 720x5, 3)</em><br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2Fbd266d10ab0a56536d0dbe47a970b19b%2FsavgolFilter300.png?generation=1700296419735057&amp;alt=media\" alt=\"\"></p>\n<p><strong>2. Feature Based on Density of Activity</strong><br>\nIt captures the anglez density within 5 min window (had to convert it to int so decimals are not counted as unique values). <br>\n<em>series_df['rolling_unique_anglez_5min_window'] = rolling_nunique_efficient(series_df['anglez_int'],60) #5 min window</em></p>\n<p>The idea was to capture sudden changes in Density.  Both the below plots are for the same series and same time frame.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2Fce3cecda8b3ccdd7363bf55baa7c0dfd%2Fanglez.png?generation=1700297968606877&amp;alt=media\" alt=\"\"><br>\nMore Density means a person is active and not Sleeping. Can be Clearly seen in rolling_unique_anglez_60min_window plot.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F44a2cc7cfa39e40b87609a5dec249ffc%2Frolling_unique_anglez_60min_window.png?generation=1700296640105302&amp;alt=media\" alt=\"\"></p>\n<p>And the sum of those unique values 30 min earlier, 25 min earlier,…. are taken to capture change in longer-term variations. can be seen in the plot.<br>\n<em>series_df['rolling_unique_anglez_5min_window'].fillna(0,inplace=True)</em><br>\n<em>series_df[\"rolling_unique_anglez_sum\"] = series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_25minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_20minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_15minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_10minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_5minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window\"]</em></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F54b241cd8dc91999b75b6abeb79b88d2%2Fanglez%20sum.png?generation=1700296219164561&amp;alt=media\" alt=\"\"></p>\n<p>After Training the LightGBM regressor, Final Predictions looks like this:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F530bba41a52fbb2f35a90e29d500f8a9%2Fprediction%20results.png?generation=1700297694516565&amp;alt=media\" alt=\"\"></p>\n<p>Thanks all, learning a lot from you guys ❤️.</p>",
  "messages": [
    {
      "id": "2529465",
      "postDate": "11/18/2023 09:15:22",
      "content": "<p>Hi Guys, I am struggling with resource and time constraints, wanted to try Temporal Fusion Transformers but Still have not been able to successfully train them. If Anybody can Share a working Temporal Fusion Transformers Kaggle Notebook with offline Imports for Reference that would be a great help. Anyways! releasing <strong>2 Most Important Features in my findings</strong>: </p>\n<p><strong>1. Smoothed AngleZ Difference using Savgol Filter in Scipy.signal</strong> <br>\nwindow size 5 hr and polynomial 3 worked for me so far.<br>\n<em>pl.col(\"anglez\").diff(1).abs().alias(\"anglez_abs_diff\")</em><br>\n<em>series_df['anglez_savgolFilter_300'] = savgol_filter(series_df['anglez_abs_diff'].copy(), 720x5, 3)</em><br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2Fbd266d10ab0a56536d0dbe47a970b19b%2FsavgolFilter300.png?generation=1700296419735057&amp;alt=media\" alt=\"\"></p>\n<p><strong>2. Feature Based on Density of Activity</strong><br>\nIt captures the anglez density within 5 min window (had to convert it to int so decimals are not counted as unique values). <br>\n<em>series_df['rolling_unique_anglez_5min_window'] = rolling_nunique_efficient(series_df['anglez_int'],60) #5 min window</em></p>\n<p>The idea was to capture sudden changes in Density.  Both the below plots are for the same series and same time frame.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2Fce3cecda8b3ccdd7363bf55baa7c0dfd%2Fanglez.png?generation=1700297968606877&amp;alt=media\" alt=\"\"><br>\nMore Density means a person is active and not Sleeping. Can be Clearly seen in rolling_unique_anglez_60min_window plot.</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F44a2cc7cfa39e40b87609a5dec249ffc%2Frolling_unique_anglez_60min_window.png?generation=1700296640105302&amp;alt=media\" alt=\"\"></p>\n<p>And the sum of those unique values 30 min earlier, 25 min earlier,…. are taken to capture change in longer-term variations. can be seen in the plot.<br>\n<em>series_df['rolling_unique_anglez_5min_window'].fillna(0,inplace=True)</em><br>\n<em>series_df[\"rolling_unique_anglez_sum\"] = series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_25minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_20minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_15minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_10minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_5minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window\"]</em></p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F54b241cd8dc91999b75b6abeb79b88d2%2Fanglez%20sum.png?generation=1700296219164561&amp;alt=media\" alt=\"\"></p>\n<p>After Training the LightGBM regressor, Final Predictions looks like this:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F530bba41a52fbb2f35a90e29d500f8a9%2Fprediction%20results.png?generation=1700297694516565&amp;alt=media\" alt=\"\"></p>\n<p>Thanks all, learning a lot from you guys ❤️.</p>",
      "rawMarkdown": "Hi Guys, I am struggling with resource and time constraints, wanted to try Temporal Fusion Transformers but Still have not been able to successfully train them. If Anybody can Share a working Temporal Fusion Transformers Kaggle Notebook with offline Imports for Reference that would be a great help. Anyways! releasing **2 Most Important Features in my findings**: \n\n**1. Smoothed AngleZ Difference using Savgol Filter in Scipy.signal** \nwindow size 5 hr and polynomial 3 worked for me so far.\n*pl.col(\"anglez\").diff(1).abs().alias(\"anglez_abs_diff\")*\n*series_df['anglez_savgolFilter_300'] = savgol_filter(series_df['anglez_abs_diff'].copy(), 720x5, 3)*\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2Fbd266d10ab0a56536d0dbe47a970b19b%2FsavgolFilter300.png?generation=1700296419735057&alt=media)\n\n**2. Feature Based on Density of Activity**\nIt captures the anglez density within 5 min window (had to convert it to int so decimals are not counted as unique values). \n*series_df['rolling_unique_anglez_5min_window'] = rolling_nunique_efficient(series_df['anglez_int'],60) #5 min window*\n\nThe idea was to capture sudden changes in Density.  Both the below plots are for the same series and same time frame.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2Fce3cecda8b3ccdd7363bf55baa7c0dfd%2Fanglez.png?generation=1700297968606877&alt=media)\nMore Density means a person is active and not Sleeping. Can be Clearly seen in rolling_unique_anglez_60min_window plot.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F44a2cc7cfa39e40b87609a5dec249ffc%2Frolling_unique_anglez_60min_window.png?generation=1700296640105302&alt=media)\n\n\nAnd the sum of those unique values 30 min earlier, 25 min earlier,.... are taken to capture change in longer-term variations. can be seen in the plot.\n*series_df['rolling_unique_anglez_5min_window'].fillna(0,inplace=True)*\n*series_df[\"rolling_unique_anglez_sum\"] = series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_25minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_20minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_15minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_10minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_5minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window\"]*\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F54b241cd8dc91999b75b6abeb79b88d2%2Fanglez%20sum.png?generation=1700296219164561&alt=media)\n\n\nAfter Training the LightGBM regressor, Final Predictions looks like this:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F530bba41a52fbb2f35a90e29d500f8a9%2Fprediction%20results.png?generation=1700297694516565&alt=media)\n\n\nThanks all, learning a lot from you guys ❤️.",
      "votes": null
    },
    {
      "id": "2529505",
      "postDate": "11/18/2023 10:11:02",
      "content": "<p>Really Nice OutComes😍</p>",
      "rawMarkdown": "Really Nice OutComes😍",
      "votes": null
    },
    {
      "id": "2529862",
      "postDate": "11/18/2023 15:48:15",
      "content": "<p>Thanks <a href=\"https://www.kaggle.com/bitguber\" target=\"_blank\">@bitguber</a> </p>",
      "rawMarkdown": "Thanks @bitguber",
      "votes": null
    },
    {
      "id": "2529938",
      "postDate": "11/18/2023 17:01:23",
      "content": "<p>Thanks for your sharing.I'll try to implement your features and make a reply later.I hope it will work.</p>",
      "rawMarkdown": "Thanks for your sharing.I'll try to implement your features and make a reply later.I hope it will work.",
      "votes": null
    },
    {
      "id": "2529964",
      "postDate": "11/18/2023 17:24:01",
      "content": "<p><a href=\"https://www.kaggle.com/hugginglook\" target=\"_blank\">@hugginglook</a> will be happy to see if it works for you. 🙂</p>",
      "rawMarkdown": "hugginglook will be happy to see if it works for you. 🙂",
      "votes": null
    },
    {
      "id": "2535038",
      "postDate": "11/23/2023 04:35:40",
      "content": "<p>When using 720x5 for inference, an error occurs due to the data size being too short. Is there a solution?</p>",
      "rawMarkdown": "When using 720x5 for inference, an error occurs due to the data size being too short. Is there a solution?",
      "votes": null
    },
    {
      "id": "2535263",
      "postDate": "11/23/2023 07:45:26",
      "content": "<p>Assuming you are trying to do this at day level. I have applied this at series level, have not tried at day level! Thought was to capture longer term general sleep pattern of a person by removing short term noise. Will suggest you to do this for whole series and then segment to get the day level patterns. Hope that helps. And let me know where this feature's importance stands in your model. See you at the top. All the best.</p>",
      "rawMarkdown": "Assuming you are trying to do this at day level. I have applied this at series level, have not tried at day level! Thought was to capture longer term general sleep pattern of a person by removing short term noise. Will suggest you to do this for whole series and then segment to get the day level patterns. Hope that helps. And let me know where this feature's importance stands in your model. See you at the top. All the best.",
      "votes": null
    },
    {
      "id": "2536250",
      "postDate": "11/24/2023 04:24:14",
      "content": "<p>Thanks for the input, I will try the rolling_unique_anglez_5min_window feature.<br>\nThe savgol filter looks also good on my model.</p>\n<p>I'm interested to understand how you create : rolling_nunique_efficient?<br>\nbecause it's very slow otherwise.</p>\n<p>Thanks</p>",
      "rawMarkdown": "Thanks for the input, I will try the rolling_unique_anglez_5min_window feature.\nThe savgol filter looks also good on my model.\n\nI'm interested to understand how you create : rolling_nunique_efficient?\nbecause it's very slow otherwise.\n\nThanks",
      "votes": null
    },
    {
      "id": "2536501",
      "postDate": "11/24/2023 08:55:36",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/alexandredurand\" target=\"_blank\">@alexandredurand</a>, It's good to hear from you that it's helping.  ref: to this function, it can still be optimized. but this reduced the time for me for the trials.</p>\n<p>def rolling_nunique_efficient(series, window):<br>\n    values = series.values<br>\n    unique_counts = np.zeros(len(values))<br>\n    unique_values = set()<br>\n    rolling_nunique_result = []<br>\n    for i in range(len(values)):<br>\n        if i &gt;= window:<br>\n            unique_values.discard(values[i - window])<br>\n        unique_values.add(values[i])<br>\n        unique_counts[i] = len(unique_values)<br>\n        if i &gt;= window - 1:<br>\n            rolling_nunique_result.append(unique_counts[i])<br>\n        else:<br>\n            rolling_nunique_result.append(np.nan)<br>\n    return pd.Series(rolling_nunique_result, index=series.index)</p>",
      "rawMarkdown": "Hi @alexandredurand, It's good to hear from you that it's helping.  ref: to this function, it can still be optimized. but this reduced the time for me for the trials.\n\ndef rolling_nunique_efficient(series, window):\n    values = series.values\n    unique_counts = np.zeros(len(values))\n    unique_values = set()\n    rolling_nunique_result = []\n    for i in range(len(values)):\n        if i >= window:\n            unique_values.discard(values[i - window])\n        unique_values.add(values[i])\n        unique_counts[i] = len(unique_values)\n        if i >= window - 1:\n            rolling_nunique_result.append(unique_counts[i])\n        else:\n            rolling_nunique_result.append(np.nan)\n    return pd.Series(rolling_nunique_result, index=series.index)",
      "votes": null
    },
    {
      "id": "2536535",
      "postDate": "11/24/2023 09:11:44",
      "content": "<p>Thanks a lot <a href=\"https://www.kaggle.com/anand815353\" target=\"_blank\">@anand815353</a> </p>\n<p>Let me try it.</p>",
      "rawMarkdown": "Thanks a lot @anand815353 \n\nLet me try it.",
      "votes": null
    },
    {
      "id": "2541781",
      "postDate": "11/28/2023 19:20:08",
      "content": "<p>Incredible, these ideas are all tangible</p>",
      "rawMarkdown": "Incredible, these ideas are all tangible",
      "votes": null
    },
    {
      "id": "2543054",
      "postDate": "11/29/2023 18:06:58",
      "content": "<p>Grateful for your creative contributions on this competition.</p>",
      "rawMarkdown": "Grateful for your creative contributions on this competition.",
      "votes": null
    },
    {
      "id": "2543700",
      "postDate": "11/30/2023 09:57:23",
      "content": "<p>Thanks for your kind words.</p>",
      "rawMarkdown": "Thanks for your kind words.",
      "votes": null
    },
    {
      "id": "2543701",
      "postDate": "11/30/2023 09:58:40",
      "content": "<p>Thanks <a href=\"https://www.kaggle.com/liushundawang\" target=\"_blank\">@liushundawang</a> </p>",
      "rawMarkdown": "Thanks @liushundawang",
      "votes": null
    },
    {
      "id": "2546626",
      "postDate": "12/02/2023 16:14:11",
      "content": "<p>Hello~, thanks again for your excellent work, I tried new feature <code>series_df['rolling_unique_anglez_5min_window'].fillna(0,inplace=True)</code> but it get worse, and I wonder <code>series_df[\"rolling_unique_anglez_sum\"] = series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_25minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_20minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_15minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_10minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_5minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window\"]</code> how do you implement to get the earlier value <code>series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]</code>? Thanks again for your splendid job.</p>",
      "rawMarkdown": "Hello~, thanks again for your excellent work, I tried new feature `series_df['rolling_unique_anglez_5min_window'].fillna(0,inplace=True)` but it get worse, and I wonder `series_df[\"rolling_unique_anglez_sum\"] = series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_25minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_20minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_15minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_10minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_5minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window\"]` how do you implement to get the earlier value `series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]`? Thanks again for your splendid job.",
      "votes": null
    },
    {
      "id": "2547163",
      "postDate": "12/03/2023 08:30:31",
      "content": "<p><a href=\"https://www.kaggle.com/brickcoder\" target=\"_blank\">@brickcoder</a> Hello, I didn't get you completely. But to clarify LightGBM regressor result that is displayed had other features as well and the importance was very high for these two among others, LIDS whose Importance as shown in public notebooks is in top 5 I guess!,  had medium Importance in this model. These are the Importance of a more recent model LightGBM regressor.<br>\n  <img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F939eee5a07385c8710cac73694863369%2FScreenshot%20importance.png?generation=1701590781439620&amp;alt=media\" alt=\"\"></p>\n<p>Also, want to add that the Critical point Regression methodology is not stable when using Lightgbm, gives out noise around the Target for all of the things that I have tried. I feel it's because of the rareity of events Regions.  Perhaps some NN can help reduce the Noise maybe!.<br>\n <img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F4dbc2628a8116d839498e0e971c429d6%2Fcritical%20point%20regression%20noise%20.png?generation=1701591611766613&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "brickcoder Hello, I didn't get you completely. But to clarify LightGBM regressor result that is displayed had other features as well and the importance was very high for these two among others, LIDS whose Importance as shown in public notebooks is in top 5 I guess!,  had medium Importance in this model. These are the Importance of a more recent model LightGBM regressor.\n  ![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F939eee5a07385c8710cac73694863369%2FScreenshot%20importance.png?generation=1701590781439620&alt=media)\n\n Also, want to add that the Critical point Regression methodology is not stable when using Lightgbm, gives out noise around the Target for all of the things that I have tried. I feel it's because of the rareity of events Regions.  Perhaps some NN can help reduce the Noise maybe!.\n ![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F4dbc2628a8116d839498e0e971c429d6%2Fcritical%20point%20regression%20noise%20.png?generation=1701591611766613&alt=media)",
      "votes": null
    },
    {
      "id": "2547323",
      "postDate": "12/03/2023 12:29:05",
      "content": "<p>Thanks for your reply, I am sorry not clarify my question. I just want to know how you get this feature <code>series_df[\"rolling_unique_anglez_5min_window_XXXminEarlier\"]</code> , I wonder how to get the \"rolling_unique_anglez_5min_window_XXXminEarlier\" feature</p>",
      "rawMarkdown": "Thanks for your reply, I am sorry not clarify my question. I just want to know how you get this feature `series_df[\"rolling_unique_anglez_5min_window_XXXminEarlier\"]` , I wonder how to get the \"rolling_unique_anglez_5min_window_XXXminEarlier\" feature",
      "votes": null
    },
    {
      "id": "2547355",
      "postDate": "12/03/2023 12:48:47",
      "content": "<p>oh! ok. just shifted \"rolling_unique_anglez_5min_window\", 60 steps downwards for 5 min (12*5).<br>\nseries[\"rolling_unique_anglez_5min_window_5minEarlier\"] = series[\"rolling_unique_anglez_5min_window\"].shift(60)</p>",
      "rawMarkdown": "oh! ok. just shifted \"rolling_unique_anglez_5min_window\", 60 steps downwards for 5 min (12*5).\nseries[\"rolling_unique_anglez_5min_window_5minEarlier\"] = series[\"rolling_unique_anglez_5min_window\"].shift(60)",
      "votes": null
    },
    {
      "id": "2547457",
      "postDate": "12/03/2023 14:19:07",
      "content": "<p>orz, thanks, I will try and give feedbacks back.💜</p>",
      "rawMarkdown": "orz, thanks, I will try and give feedbacks back.💜",
      "votes": null
    },
    {
      "id": "2548648",
      "postDate": "12/04/2023 15:23:19",
      "content": "<p>Tried, hh ,not works very well on my DL models. But it's really interesting! </p>",
      "rawMarkdown": "Tried, hh ,not works very well on my DL models. But it's really interesting!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2529505,
      "author_name": "bitguber",
      "author_url": "",
      "post_date": "11/18/2023 10:11:02",
      "content": "<p>Really Nice OutComes😍</p>",
      "votes": null,
      "replies": [
        {
          "id": 2529862,
          "author_name": "anand815353",
          "author_url": "",
          "post_date": "11/18/2023 15:48:15",
          "content": "<p>Thanks <a href=\"https://www.kaggle.com/bitguber\" target=\"_blank\">@bitguber</a> </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2529938,
      "author_name": "hugginglook",
      "author_url": "",
      "post_date": "11/18/2023 17:01:23",
      "content": "<p>Thanks for your sharing.I'll try to implement your features and make a reply later.I hope it will work.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2529964,
          "author_name": "anand815353",
          "author_url": "",
          "post_date": "11/18/2023 17:24:01",
          "content": "<p><a href=\"https://www.kaggle.com/hugginglook\" target=\"_blank\">@hugginglook</a> will be happy to see if it works for you. 🙂</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2535038,
      "author_name": "daichi1412",
      "author_url": "",
      "post_date": "11/23/2023 04:35:40",
      "content": "<p>When using 720x5 for inference, an error occurs due to the data size being too short. Is there a solution?</p>",
      "votes": null,
      "replies": [
        {
          "id": 2535263,
          "author_name": "anand815353",
          "author_url": "",
          "post_date": "11/23/2023 07:45:26",
          "content": "<p>Assuming you are trying to do this at day level. I have applied this at series level, have not tried at day level! Thought was to capture longer term general sleep pattern of a person by removing short term noise. Will suggest you to do this for whole series and then segment to get the day level patterns. Hope that helps. And let me know where this feature's importance stands in your model. See you at the top. All the best.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2536250,
      "author_name": "alexandredurand",
      "author_url": "",
      "post_date": "11/24/2023 04:24:14",
      "content": "<p>Thanks for the input, I will try the rolling_unique_anglez_5min_window feature.<br>\nThe savgol filter looks also good on my model.</p>\n<p>I'm interested to understand how you create : rolling_nunique_efficient?<br>\nbecause it's very slow otherwise.</p>\n<p>Thanks</p>",
      "votes": null,
      "replies": [
        {
          "id": 2536501,
          "author_name": "anand815353",
          "author_url": "",
          "post_date": "11/24/2023 08:55:36",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/alexandredurand\" target=\"_blank\">@alexandredurand</a>, It's good to hear from you that it's helping.  ref: to this function, it can still be optimized. but this reduced the time for me for the trials.</p>\n<p>def rolling_nunique_efficient(series, window):<br>\n    values = series.values<br>\n    unique_counts = np.zeros(len(values))<br>\n    unique_values = set()<br>\n    rolling_nunique_result = []<br>\n    for i in range(len(values)):<br>\n        if i &gt;= window:<br>\n            unique_values.discard(values[i - window])<br>\n        unique_values.add(values[i])<br>\n        unique_counts[i] = len(unique_values)<br>\n        if i &gt;= window - 1:<br>\n            rolling_nunique_result.append(unique_counts[i])<br>\n        else:<br>\n            rolling_nunique_result.append(np.nan)<br>\n    return pd.Series(rolling_nunique_result, index=series.index)</p>",
          "votes": null,
          "replies": [
            {
              "id": 2536535,
              "author_name": "alexandredurand",
              "author_url": "",
              "post_date": "11/24/2023 09:11:44",
              "content": "<p>Thanks a lot <a href=\"https://www.kaggle.com/anand815353\" target=\"_blank\">@anand815353</a> </p>\n<p>Let me try it.</p>",
              "votes": null,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2541781,
      "author_name": "liushundawang",
      "author_url": "",
      "post_date": "11/28/2023 19:20:08",
      "content": "<p>Incredible, these ideas are all tangible</p>",
      "votes": null,
      "replies": [
        {
          "id": 2543701,
          "author_name": "anand815353",
          "author_url": "",
          "post_date": "11/30/2023 09:58:40",
          "content": "<p>Thanks <a href=\"https://www.kaggle.com/liushundawang\" target=\"_blank\">@liushundawang</a> </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2543054,
      "author_name": "brickcoder",
      "author_url": "",
      "post_date": "11/29/2023 18:06:58",
      "content": "<p>Grateful for your creative contributions on this competition.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2543700,
          "author_name": "anand815353",
          "author_url": "",
          "post_date": "11/30/2023 09:57:23",
          "content": "<p>Thanks for your kind words.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2546626,
      "author_name": "brickcoder",
      "author_url": "",
      "post_date": "12/02/2023 16:14:11",
      "content": "<p>Hello~, thanks again for your excellent work, I tried new feature <code>series_df['rolling_unique_anglez_5min_window'].fillna(0,inplace=True)</code> but it get worse, and I wonder <code>series_df[\"rolling_unique_anglez_sum\"] = series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_25minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_20minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_15minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_10minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_5minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window\"]</code> how do you implement to get the earlier value <code>series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]</code>? Thanks again for your splendid job.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2547163,
          "author_name": "anand815353",
          "author_url": "",
          "post_date": "12/03/2023 08:30:31",
          "content": "<p><a href=\"https://www.kaggle.com/brickcoder\" target=\"_blank\">@brickcoder</a> Hello, I didn't get you completely. But to clarify LightGBM regressor result that is displayed had other features as well and the importance was very high for these two among others, LIDS whose Importance as shown in public notebooks is in top 5 I guess!,  had medium Importance in this model. These are the Importance of a more recent model LightGBM regressor.<br>\n  <img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F939eee5a07385c8710cac73694863369%2FScreenshot%20importance.png?generation=1701590781439620&amp;alt=media\" alt=\"\"></p>\n<p>Also, want to add that the Critical point Regression methodology is not stable when using Lightgbm, gives out noise around the Target for all of the things that I have tried. I feel it's because of the rareity of events Regions.  Perhaps some NN can help reduce the Noise maybe!.<br>\n <img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F4dbc2628a8116d839498e0e971c429d6%2Fcritical%20point%20regression%20noise%20.png?generation=1701591611766613&amp;alt=media\" alt=\"\"></p>",
          "votes": null,
          "replies": [
            {
              "id": 2547323,
              "author_name": "brickcoder",
              "author_url": "",
              "post_date": "12/03/2023 12:29:05",
              "content": "<p>Thanks for your reply, I am sorry not clarify my question. I just want to know how you get this feature <code>series_df[\"rolling_unique_anglez_5min_window_XXXminEarlier\"]</code> , I wonder how to get the \"rolling_unique_anglez_5min_window_XXXminEarlier\" feature</p>",
              "votes": null,
              "replies": [
                {
                  "id": 2547355,
                  "author_name": "anand815353",
                  "author_url": "",
                  "post_date": "12/03/2023 12:48:47",
                  "content": "<p>oh! ok. just shifted \"rolling_unique_anglez_5min_window\", 60 steps downwards for 5 min (12*5).<br>\nseries[\"rolling_unique_anglez_5min_window_5minEarlier\"] = series[\"rolling_unique_anglez_5min_window\"].shift(60)</p>",
                  "votes": null,
                  "replies": [
                    {
                      "id": 2547457,
                      "author_name": "brickcoder",
                      "author_url": "",
                      "post_date": "12/03/2023 14:19:07",
                      "content": "<p>orz, thanks, I will try and give feedbacks back.💜</p>",
                      "votes": null,
                      "replies": [
                        {
                          "id": 2548648,
                          "author_name": "liruiqi577",
                          "author_url": "",
                          "post_date": "12/04/2023 15:23:19",
                          "content": "<p>Tried, hh ,not works very well on my DL models. But it's really interesting! </p>",
                          "votes": null,
                          "replies": []
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2529465": "Hi Guys, I am struggling with resource and time constraints, wanted to try Temporal Fusion Transformers but Still have not been able to successfully train them. If Anybody can Share a working Temporal Fusion Transformers Kaggle Notebook with offline Imports for Reference that would be a great help. Anyways! releasing **2 Most Important Features in my findings**: \n\n**1. Smoothed AngleZ Difference using Savgol Filter in Scipy.signal** \nwindow size 5 hr and polynomial 3 worked for me so far.\n*pl.col(\"anglez\").diff(1).abs().alias(\"anglez_abs_diff\")*\n*series_df['anglez_savgolFilter_300'] = savgol_filter(series_df['anglez_abs_diff'].copy(), 720x5, 3)*\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2Fbd266d10ab0a56536d0dbe47a970b19b%2FsavgolFilter300.png?generation=1700296419735057&alt=media)\n\n**2. Feature Based on Density of Activity**\nIt captures the anglez density within 5 min window (had to convert it to int so decimals are not counted as unique values). \n*series_df['rolling_unique_anglez_5min_window'] = rolling_nunique_efficient(series_df['anglez_int'],60) #5 min window*\n\nThe idea was to capture sudden changes in Density.  Both the below plots are for the same series and same time frame.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2Fce3cecda8b3ccdd7363bf55baa7c0dfd%2Fanglez.png?generation=1700297968606877&alt=media)\nMore Density means a person is active and not Sleeping. Can be Clearly seen in rolling_unique_anglez_60min_window plot.\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F44a2cc7cfa39e40b87609a5dec249ffc%2Frolling_unique_anglez_60min_window.png?generation=1700296640105302&alt=media)\n\n\nAnd the sum of those unique values 30 min earlier, 25 min earlier,.... are taken to capture change in longer-term variations. can be seen in the plot.\n*series_df['rolling_unique_anglez_5min_window'].fillna(0,inplace=True)*\n*series_df[\"rolling_unique_anglez_sum\"] = series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_25minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_20minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_15minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_10minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_5minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window\"]*\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F54b241cd8dc91999b75b6abeb79b88d2%2Fanglez%20sum.png?generation=1700296219164561&alt=media)\n\n\nAfter Training the LightGBM regressor, Final Predictions looks like this:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F530bba41a52fbb2f35a90e29d500f8a9%2Fprediction%20results.png?generation=1700297694516565&alt=media)\n\n\nThanks all, learning a lot from you guys ❤️.",
    "2529505": "Really Nice OutComes😍",
    "2529862": "Thanks @bitguber",
    "2529938": "Thanks for your sharing.I'll try to implement your features and make a reply later.I hope it will work.",
    "2529964": "hugginglook will be happy to see if it works for you. 🙂",
    "2535038": "When using 720x5 for inference, an error occurs due to the data size being too short. Is there a solution?",
    "2535263": "Assuming you are trying to do this at day level. I have applied this at series level, have not tried at day level! Thought was to capture longer term general sleep pattern of a person by removing short term noise. Will suggest you to do this for whole series and then segment to get the day level patterns. Hope that helps. And let me know where this feature's importance stands in your model. See you at the top. All the best.",
    "2536250": "Thanks for the input, I will try the rolling_unique_anglez_5min_window feature.\nThe savgol filter looks also good on my model.\n\nI'm interested to understand how you create : rolling_nunique_efficient?\nbecause it's very slow otherwise.\n\nThanks",
    "2536501": "Hi @alexandredurand, It's good to hear from you that it's helping.  ref: to this function, it can still be optimized. but this reduced the time for me for the trials.\n\ndef rolling_nunique_efficient(series, window):\n    values = series.values\n    unique_counts = np.zeros(len(values))\n    unique_values = set()\n    rolling_nunique_result = []\n    for i in range(len(values)):\n        if i >= window:\n            unique_values.discard(values[i - window])\n        unique_values.add(values[i])\n        unique_counts[i] = len(unique_values)\n        if i >= window - 1:\n            rolling_nunique_result.append(unique_counts[i])\n        else:\n            rolling_nunique_result.append(np.nan)\n    return pd.Series(rolling_nunique_result, index=series.index)",
    "2536535": "Thanks a lot @anand815353 \n\nLet me try it.",
    "2541781": "Incredible, these ideas are all tangible",
    "2543054": "Grateful for your creative contributions on this competition.",
    "2543700": "Thanks for your kind words.",
    "2543701": "Thanks @liushundawang",
    "2546626": "Hello~, thanks again for your excellent work, I tried new feature `series_df['rolling_unique_anglez_5min_window'].fillna(0,inplace=True)` but it get worse, and I wonder `series_df[\"rolling_unique_anglez_sum\"] = series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_25minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_20minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_15minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_10minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window_5minEarlier\"]+series_df[\"rolling_unique_anglez_5min_window\"]` how do you implement to get the earlier value `series_df[\"rolling_unique_anglez_5min_window_30minEarlier\"]`? Thanks again for your splendid job.",
    "2547163": "brickcoder Hello, I didn't get you completely. But to clarify LightGBM regressor result that is displayed had other features as well and the importance was very high for these two among others, LIDS whose Importance as shown in public notebooks is in top 5 I guess!,  had medium Importance in this model. These are the Importance of a more recent model LightGBM regressor.\n  ![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F939eee5a07385c8710cac73694863369%2FScreenshot%20importance.png?generation=1701590781439620&alt=media)\n\n Also, want to add that the Critical point Regression methodology is not stable when using Lightgbm, gives out noise around the Target for all of the things that I have tried. I feel it's because of the rareity of events Regions.  Perhaps some NN can help reduce the Noise maybe!.\n ![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F4583131%2F4dbc2628a8116d839498e0e971c429d6%2Fcritical%20point%20regression%20noise%20.png?generation=1701591611766613&alt=media)",
    "2547323": "Thanks for your reply, I am sorry not clarify my question. I just want to know how you get this feature `series_df[\"rolling_unique_anglez_5min_window_XXXminEarlier\"]` , I wonder how to get the \"rolling_unique_anglez_5min_window_XXXminEarlier\" feature",
    "2547355": "oh! ok. just shifted \"rolling_unique_anglez_5min_window\", 60 steps downwards for 5 min (12*5).\nseries[\"rolling_unique_anglez_5min_window_5minEarlier\"] = series[\"rolling_unique_anglez_5min_window\"].shift(60)",
    "2547457": "orz, thanks, I will try and give feedbacks back.💜",
    "2548648": "Tried, hh ,not works very well on my DL models. But it's really interesting!"
  },
  "source": "meta"
}