{
  "id": 448683,
  "title": "Data Inconsistency",
  "url": "/competitions/child-mind-institute-detect-sleep-states/discussion/448683",
  "author_name": "",
  "post_date": "2023-10-20T17:32:08.757401400Z",
  "votes": 11,
  "comment_count": 21,
  "views": 0,
  "content": "<p><a href=\"https://www.kaggle.com/ryanholbrook\" target=\"_blank\">@ryanholbrook</a> could you check if there are still data inconsistencies after the data update? For instance, I found for series <code>2f7504d0f426</code> that there is 1 hour missing between steps <code>200879</code> and <code>200880</code>:</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3197853%2Fb338eb4a93e0a38e605baba4616f14e3%2FScreen%20Shot%202023-10-20%20at%2014.26.21.png?generation=1697822938043936&amp;alt=media\" alt=\"\"></p>\n<p>Thanks :)</p>",
  "messages": [
    {
      "id": "2490458",
      "postDate": "10/20/2023 17:32:08",
      "content": "<p><a href=\"https://www.kaggle.com/ryanholbrook\" target=\"_blank\">@ryanholbrook</a> could you check if there are still data inconsistencies after the data update? For instance, I found for series <code>2f7504d0f426</code> that there is 1 hour missing between steps <code>200879</code> and <code>200880</code>:</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3197853%2Fb338eb4a93e0a38e605baba4616f14e3%2FScreen%20Shot%202023-10-20%20at%2014.26.21.png?generation=1697822938043936&amp;alt=media\" alt=\"\"></p>\n<p>Thanks :)</p>",
      "rawMarkdown": "ryanholbrook could you check if there are still data inconsistencies after the data update? For instance, I found for series `2f7504d0f426` that there is 1 hour missing between steps `200879` and `200880`:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3197853%2Fb338eb4a93e0a38e605baba4616f14e3%2FScreen%20Shot%202023-10-20%20at%2014.26.21.png?generation=1697822938043936&alt=media)\n\nThanks :)",
      "votes": null
    },
    {
      "id": "2490469",
      "postDate": "10/20/2023 17:51:32",
      "content": "<p>I was going to suggest that was when daylight saving time switched over (it's at 2am in the Spring, so losing an hour), but Google says Daylight savings time in 2018 was on March 11, not March 18. yes, odd.</p>",
      "rawMarkdown": "I was going to suggest that was when daylight saving time switched over (it's at 2am in the Spring, so losing an hour), but Google says Daylight savings time in 2018 was on March 11, not March 18. yes, odd.",
      "votes": null
    },
    {
      "id": "2490500",
      "postDate": "10/20/2023 18:11:33",
      "content": "<p>Some other weird series: <br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3197853%2F0f0b1e571e2da57c74fe18537bbd726c%2FScreen%20Shot%202023-10-20%20at%2015.10.51.png?generation=1697825480730381&amp;alt=media\" alt=\"\"></p>\n<p>This one goes back and forth in time.</p>",
      "rawMarkdown": "Some other weird series: \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3197853%2F0f0b1e571e2da57c74fe18537bbd726c%2FScreen%20Shot%202023-10-20%20at%2015.10.51.png?generation=1697825480730381&alt=media)\n\nThis one goes back and forth in time.",
      "votes": null
    },
    {
      "id": "2490509",
      "postDate": "10/20/2023 18:18:01",
      "content": "<p>I think that data should be checked for consecutive jumps of 5 seconds. If not, the data is wrong</p>",
      "rawMarkdown": "I think that data should be checked for consecutive jumps of 5 seconds. If not, the data is wrong",
      "votes": null
    },
    {
      "id": "2490514",
      "postDate": "10/20/2023 18:24:48",
      "content": "<p>So that one matches with daylight savings time ending in 2018, but is also a week off (It was Nov 4, not Nov 11 that year). So it looks like the data could be all a week off?</p>",
      "rawMarkdown": "So that one matches with daylight savings time ending in 2018, but is also a week off (It was Nov 4, not Nov 11 that year). So it looks like the data could be all a week off?",
      "votes": null
    },
    {
      "id": "2490551",
      "postDate": "10/20/2023 19:17:55",
      "content": "<p>I truly don't know, but I have found numerous cases where there's either data missing or these \"back in time\" cases</p>",
      "rawMarkdown": "I truly don't know, but I have found numerous cases where there's either data missing or these \"back in time\" cases",
      "votes": null
    },
    {
      "id": "2490626",
      "postDate": "10/20/2023 20:56:08",
      "content": "<p>There is no time missing. Row 25209359 is 1:59:55 and timezone UTC-5. Then the next row 25209360 is 3:00:00 and timezone UTC-4. If we convert both to UTC time zone, then the first is 6:59:55 and the second is 7:00:00</p>\n<p>When converting this column from string to datetime, we need to convert everything to the same timezone. I have confirmed that the entire train data has 5 second gap between every consecutive row.</p>",
      "rawMarkdown": "There is no time missing. Row 25209359 is 1:59:55 and timezone UTC-5. Then the next row 25209360 is 3:00:00 and timezone UTC-4. If we convert both to UTC time zone, then the first is 6:59:55 and the second is 7:00:00\n\nWhen converting this column from string to datetime, we need to convert everything to the same timezone. I have confirmed that the entire train data has 5 second gap between every consecutive row.",
      "votes": null
    },
    {
      "id": "2490690",
      "postDate": "10/21/2023 00:15:41",
      "content": "<p>Thanks Chris, I am using datetime’s strptime method. Maybe its an issue with this conversion method. Which one are you using?</p>",
      "rawMarkdown": "Thanks Chris, I am using datetime’s strptime method. Maybe its an issue with this conversion method. Which one are you using?",
      "votes": null
    },
    {
      "id": "2491092",
      "postDate": "10/21/2023 10:22:47",
      "content": "<p>Perhaps they crossed a timezone border?</p>",
      "rawMarkdown": "Perhaps they crossed a timezone border?",
      "votes": null
    },
    {
      "id": "2491341",
      "postDate": "10/21/2023 14:33:35",
      "content": "<p>I'm using <code>cudf.to_datetime()</code> which converts everything to UTC timezone (and afterward every row is 5 seconds difference). I've noticed that the <code>pd.to_datetime()</code> does not convert everything to the same timezone. Pandas keeps the original timezones.</p>\n<p>With Pandas we can do the following to cast all times to UTC timezone. Then we will see no gaps in <code>df.timestamp.dt.hour</code>:</p>\n<pre><code>import pytz\ndefault_datetime = \ndf = df(default_datetime)\ndf = pd(df, format=)\ndf = df(lambda x: x(pytz.utc))\ndf = pd\n</code></pre>",
      "rawMarkdown": "I'm using `cudf.to_datetime()` which converts everything to UTC timezone (and afterward every row is 5 seconds difference). I've noticed that the `pd.to_datetime()` does not convert everything to the same timezone. Pandas keeps the original timezones.\n\nWith Pandas we can do the following to cast all times to UTC timezone. Then we will see no gaps in `df.timestamp.dt.hour`:\n\n    import pytz\n    default_datetime = \"1970-01-01T00:00:00+0000\"\n    df['timestamp'] = df['timestamp'].fillna(default_datetime)\n    df['timestamp'] = pd.to_datetime(df['timestamp'], format='%Y-%m-%dT%H:%M:%S%z')\n    df['timestamp'] = df['timestamp'].apply(lambda x: x.astimezone(pytz.utc))\n    df.loc[df.timestamp.dt.year==1970,'timestamp'] = pd.NaT",
      "votes": null
    },
    {
      "id": "2491345",
      "postDate": "10/21/2023 14:36:56",
      "content": "<p><a href=\"https://www.kaggle.com/moth\" target=\"_blank\">@moth</a>: There is a Daylight Time Saving (DTS) change labelling issue in the timestamps of the raw dataset. It is the root cause of what you see (and, yes, it does not manifest if you cast the timestamps to UTC). You may follow the notebook per <a href=\"https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check\" target=\"_blank\">https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check</a>  for the full assessment/analysis of this problem.</p>",
      "rawMarkdown": "moth: There is a Daylight Time Saving (DTS) change labelling issue in the timestamps of the raw dataset. It is the root cause of what you see (and, yes, it does not manifest if you cast the timestamps to UTC). You may follow the notebook per https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check  for the full assessment/analysis of this problem.",
      "votes": null
    },
    {
      "id": "2491348",
      "postDate": "10/21/2023 14:38:28",
      "content": "<p><a href=\"https://www.kaggle.com/chris62\" target=\"_blank\">@chris62</a> , <a href=\"https://www.kaggle.com/alejopaullier\" target=\"_blank\">@alejopaullier</a> : yes, the root cause of this issue is the wrong DST change date used in the raw dataset. You can <a href=\"https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check\" target=\"_blank\">https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check</a> for more detailed analysis of the glitch.</p>",
      "rawMarkdown": "chris62 , @alejopaullier : yes, the root cause of this issue is the wrong DST change date used in the raw dataset. You can https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check for more detailed analysis of the glitch.",
      "votes": null
    },
    {
      "id": "2491350",
      "postDate": "10/21/2023 14:40:39",
      "content": "<p><a href=\"https://www.kaggle.com/fritzcremer\" target=\"_blank\">@fritzcremer</a> : yes, crossing the DST change  dates (along with the wrong DST change dates used in the raw timestamps) is the reason for the issues observed. I posted the  link to my notebook with the detailed analysis of the problem in earlier comments to this thread.</p>",
      "rawMarkdown": "fritzcremer : yes, crossing the DST change  dates (along with the wrong DST change dates used in the raw timestamps) is the reason for the issues observed. I posted the  link to my notebook with the detailed analysis of the problem in earlier comments to this thread.",
      "votes": null
    },
    {
      "id": "2491379",
      "postDate": "10/21/2023 15:23:06",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/alejopaullier\" target=\"_blank\">@alejopaullier</a>, not sure if this is still an issue for you. However I tried using <code>cudf</code> as per <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> but it runs out of memory on kaggle (I assume he's using his own hardware). However when loading the data using polars, adding <code>time_zone='UTC'</code> fixes this problem (as shown below):</p>\n<pre><code>import polars  pl\n\ndt_transforms = \n\ntrn_series = (\n    pl.scan\n    .)\n    .collect\n    .\n)\n</code></pre>\n<p>And the results look like:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F557179%2F8e04b6e820806ba60fe87b1c7ac880b1%2FScreenshot%202023-10-21%20at%2011.19.32%20AM.png?generation=1697901601310187&amp;alt=media\" alt=\"fixed series 3c336d6ba566\"></p>\n<p>This also seems to be fairly fast and can be applied during submission.</p>",
      "rawMarkdown": "Hi @alejopaullier, not sure if this is still an issue for you. However I tried using `cudf` as per @cdeotte but it runs out of memory on kaggle (I assume he's using his own hardware). However when loading the data using polars, adding `time_zone='UTC'` fixes this problem (as shown below):\n\n```\nimport polars as pl\n\ndt_transforms = [\n    pl.col('timestamp').str.to_datetime(time_zone='UTC'), \n    (pl.col('timestamp').str.to_datetime().dt.date()).alias('date'), \n    pl.col('timestamp').str.to_datetime().dt.time().alias('time')\n]\n\ntrn_series = (\n    pl.scan_parquet('/kaggle/input/child-mind-institute-detect-sleep-states/train_series.parquet')\n    .with_columns((dt_transforms))\n    .collect()\n    .to_pandas()\n)\n```\n\nAnd the results look like:\n![fixed series 3c336d6ba566](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F557179%2F8e04b6e820806ba60fe87b1c7ac880b1%2FScreenshot%202023-10-21%20at%2011.19.32%20AM.png?generation=1697901601310187&alt=media)\n\nThis also seems to be fairly fast and can be applied during submission.",
      "votes": null
    },
    {
      "id": "2491388",
      "postDate": "10/21/2023 15:34:19",
      "content": "<p><a href=\"https://www.kaggle.com/jjinho\" target=\"_blank\">@jjinho</a> The best way to use cuDF is to split the original parquet into 277 parquets (one per <code>series_id</code>) with code <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/447593\" target=\"_blank\">here</a>. Afterward we load one <code>series_id</code> parquet at a time with cuDF, then create features, then save result to disk as NumPy, then clear memory. Then to train our model, we load all <code>series_id</code> NumPys and concatenate into train data.</p>",
      "rawMarkdown": "jjinho The best way to use cuDF is to split the original parquet into 277 parquets (one per `series_id`) with code [here][1]. Afterward we load one `series_id` parquet at a time with cuDF, then create features, then save result to disk as NumPy, then clear memory. Then to train our model, we load all `series_id` NumPys and concatenate into train data.\n\n[1]: https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/447593",
      "votes": null
    },
    {
      "id": "2491393",
      "postDate": "10/21/2023 15:37:12",
      "content": "<p>Thanks <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a>, that makes total sense. I missed that. And for future reference, when using cuDF, if we use the T4x2 environment, does it automatically divide data over both GPUs?</p>",
      "rawMarkdown": "Thanks @cdeotte, that makes total sense. I missed that. And for future reference, when using cuDF, if we use the T4x2 environment, does it automatically divide data over both GPUs?",
      "votes": null
    },
    {
      "id": "2491417",
      "postDate": "10/21/2023 15:50:05",
      "content": "<p>No, cuDF by itself will only use 1 GPU. To use 2xGPU, we need to use DASK-cuDF (which allows us to write code same as cuDF but behind the scenes DASK will utilize all GPU).</p>\n<p>One of these days, i will publish a DASK demo. There is also DASK-XGB which is XGB that uses all GPUs.</p>",
      "rawMarkdown": "No, cuDF by itself will only use 1 GPU. To use 2xGPU, we need to use DASK-cuDF (which allows us to write code same as cuDF but behind the scenes DASK will utilize all GPU).\n\nOne of these days, i will publish a DASK demo. There is also DASK-XGB which is XGB that uses all GPUs.",
      "votes": null
    },
    {
      "id": "2491425",
      "postDate": "10/21/2023 15:52:27",
      "content": "<p>Thanks for clarifying that and looking forward to seeing that demo.</p>",
      "rawMarkdown": "Thanks for clarifying that and looking forward to seeing that demo.",
      "votes": null
    },
    {
      "id": "2491487",
      "postDate": "10/21/2023 16:53:15",
      "content": "<p>By any chance has anyone taken the time to make a train dataset with the correct timestamp or at least slices? I used Andrada’s but the timestamps are wrong. I had to refactor all my code</p>",
      "rawMarkdown": "By any chance has anyone taken the time to make a train dataset with the correct timestamp or at least slices? I used Andrada’s but the timestamps are wrong. I had to refactor all my code",
      "votes": null
    },
    {
      "id": "2491492",
      "postDate": "10/21/2023 17:00:22",
      "content": "<p>Thanks <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> after concatenating all numpy arrays when training, do you use polars to convert the array into a dataframe?</p>",
      "rawMarkdown": "Thanks @cdeotte after concatenating all numpy arrays when training, do you use polars to convert the array into a dataframe?",
      "votes": null
    },
    {
      "id": "2491529",
      "postDate": "10/21/2023 17:25:56",
      "content": "<p>No, i train directly with NumPy arrays.</p>",
      "rawMarkdown": "No, i train directly with NumPy arrays.",
      "votes": null
    },
    {
      "id": "2491555",
      "postDate": "10/21/2023 17:47:04",
      "content": "<p>I saved the outputs here: <a href=\"https://www.kaggle.com/code/jjinho/simple-utc-conversion-using-polars\" target=\"_blank\">https://www.kaggle.com/code/jjinho/simple-utc-conversion-using-polars</a></p>",
      "rawMarkdown": "I saved the outputs here: https://www.kaggle.com/code/jjinho/simple-utc-conversion-using-polars",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2490469,
      "author_name": "chris62",
      "author_url": "",
      "post_date": "10/20/2023 17:51:32",
      "content": "<p>I was going to suggest that was when daylight saving time switched over (it's at 2am in the Spring, so losing an hour), but Google says Daylight savings time in 2018 was on March 11, not March 18. yes, odd.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2491092,
          "author_name": "fritzcremer",
          "author_url": "",
          "post_date": "10/21/2023 10:22:47",
          "content": "<p>Perhaps they crossed a timezone border?</p>",
          "votes": null,
          "replies": [
            {
              "id": 2491350,
              "author_name": "gvyshnya",
              "author_url": "",
              "post_date": "10/21/2023 14:40:39",
              "content": "<p><a href=\"https://www.kaggle.com/fritzcremer\" target=\"_blank\">@fritzcremer</a> : yes, crossing the DST change  dates (along with the wrong DST change dates used in the raw timestamps) is the reason for the issues observed. I posted the  link to my notebook with the detailed analysis of the problem in earlier comments to this thread.</p>",
              "votes": null,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2490500,
      "author_name": "alejopaullier",
      "author_url": "",
      "post_date": "10/20/2023 18:11:33",
      "content": "<p>Some other weird series: <br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3197853%2F0f0b1e571e2da57c74fe18537bbd726c%2FScreen%20Shot%202023-10-20%20at%2015.10.51.png?generation=1697825480730381&amp;alt=media\" alt=\"\"></p>\n<p>This one goes back and forth in time.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2490514,
          "author_name": "chris62",
          "author_url": "",
          "post_date": "10/20/2023 18:24:48",
          "content": "<p>So that one matches with daylight savings time ending in 2018, but is also a week off (It was Nov 4, not Nov 11 that year). So it looks like the data could be all a week off?</p>",
          "votes": null,
          "replies": [
            {
              "id": 2490551,
              "author_name": "alejopaullier",
              "author_url": "",
              "post_date": "10/20/2023 19:17:55",
              "content": "<p>I truly don't know, but I have found numerous cases where there's either data missing or these \"back in time\" cases</p>",
              "votes": null,
              "replies": [
                {
                  "id": 2491348,
                  "author_name": "gvyshnya",
                  "author_url": "",
                  "post_date": "10/21/2023 14:38:28",
                  "content": "<p><a href=\"https://www.kaggle.com/chris62\" target=\"_blank\">@chris62</a> , <a href=\"https://www.kaggle.com/alejopaullier\" target=\"_blank\">@alejopaullier</a> : yes, the root cause of this issue is the wrong DST change date used in the raw dataset. You can <a href=\"https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check\" target=\"_blank\">https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check</a> for more detailed analysis of the glitch.</p>",
                  "votes": null,
                  "replies": []
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": 2490509,
      "author_name": "alejopaullier",
      "author_url": "",
      "post_date": "10/20/2023 18:18:01",
      "content": "<p>I think that data should be checked for consecutive jumps of 5 seconds. If not, the data is wrong</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 2490626,
      "author_name": "cdeotte",
      "author_url": "",
      "post_date": "10/20/2023 20:56:08",
      "content": "<p>There is no time missing. Row 25209359 is 1:59:55 and timezone UTC-5. Then the next row 25209360 is 3:00:00 and timezone UTC-4. If we convert both to UTC time zone, then the first is 6:59:55 and the second is 7:00:00</p>\n<p>When converting this column from string to datetime, we need to convert everything to the same timezone. I have confirmed that the entire train data has 5 second gap between every consecutive row.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2490690,
          "author_name": "alejopaullier",
          "author_url": "",
          "post_date": "10/21/2023 00:15:41",
          "content": "<p>Thanks Chris, I am using datetime’s strptime method. Maybe its an issue with this conversion method. Which one are you using?</p>",
          "votes": null,
          "replies": [
            {
              "id": 2491341,
              "author_name": "cdeotte",
              "author_url": "",
              "post_date": "10/21/2023 14:33:35",
              "content": "<p>I'm using <code>cudf.to_datetime()</code> which converts everything to UTC timezone (and afterward every row is 5 seconds difference). I've noticed that the <code>pd.to_datetime()</code> does not convert everything to the same timezone. Pandas keeps the original timezones.</p>\n<p>With Pandas we can do the following to cast all times to UTC timezone. Then we will see no gaps in <code>df.timestamp.dt.hour</code>:</p>\n<pre><code>import pytz\ndefault_datetime = \ndf = df(default_datetime)\ndf = pd(df, format=)\ndf = df(lambda x: x(pytz.utc))\ndf = pd\n</code></pre>",
              "votes": null,
              "replies": []
            },
            {
              "id": 2491345,
              "author_name": "gvyshnya",
              "author_url": "",
              "post_date": "10/21/2023 14:36:56",
              "content": "<p><a href=\"https://www.kaggle.com/moth\" target=\"_blank\">@moth</a>: There is a Daylight Time Saving (DTS) change labelling issue in the timestamps of the raw dataset. It is the root cause of what you see (and, yes, it does not manifest if you cast the timestamps to UTC). You may follow the notebook per <a href=\"https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check\" target=\"_blank\">https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check</a>  for the full assessment/analysis of this problem.</p>",
              "votes": null,
              "replies": []
            },
            {
              "id": 2491379,
              "author_name": "jjinho",
              "author_url": "",
              "post_date": "10/21/2023 15:23:06",
              "content": "<p>Hi <a href=\"https://www.kaggle.com/alejopaullier\" target=\"_blank\">@alejopaullier</a>, not sure if this is still an issue for you. However I tried using <code>cudf</code> as per <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> but it runs out of memory on kaggle (I assume he's using his own hardware). However when loading the data using polars, adding <code>time_zone='UTC'</code> fixes this problem (as shown below):</p>\n<pre><code>import polars  pl\n\ndt_transforms = \n\ntrn_series = (\n    pl.scan\n    .)\n    .collect\n    .\n)\n</code></pre>\n<p>And the results look like:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F557179%2F8e04b6e820806ba60fe87b1c7ac880b1%2FScreenshot%202023-10-21%20at%2011.19.32%20AM.png?generation=1697901601310187&amp;alt=media\" alt=\"fixed series 3c336d6ba566\"></p>\n<p>This also seems to be fairly fast and can be applied during submission.</p>",
              "votes": null,
              "replies": [
                {
                  "id": 2491388,
                  "author_name": "cdeotte",
                  "author_url": "",
                  "post_date": "10/21/2023 15:34:19",
                  "content": "<p><a href=\"https://www.kaggle.com/jjinho\" target=\"_blank\">@jjinho</a> The best way to use cuDF is to split the original parquet into 277 parquets (one per <code>series_id</code>) with code <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/447593\" target=\"_blank\">here</a>. Afterward we load one <code>series_id</code> parquet at a time with cuDF, then create features, then save result to disk as NumPy, then clear memory. Then to train our model, we load all <code>series_id</code> NumPys and concatenate into train data.</p>",
                  "votes": null,
                  "replies": [
                    {
                      "id": 2491393,
                      "author_name": "jjinho",
                      "author_url": "",
                      "post_date": "10/21/2023 15:37:12",
                      "content": "<p>Thanks <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a>, that makes total sense. I missed that. And for future reference, when using cuDF, if we use the T4x2 environment, does it automatically divide data over both GPUs?</p>",
                      "votes": null,
                      "replies": [
                        {
                          "id": 2491417,
                          "author_name": "cdeotte",
                          "author_url": "",
                          "post_date": "10/21/2023 15:50:05",
                          "content": "<p>No, cuDF by itself will only use 1 GPU. To use 2xGPU, we need to use DASK-cuDF (which allows us to write code same as cuDF but behind the scenes DASK will utilize all GPU).</p>\n<p>One of these days, i will publish a DASK demo. There is also DASK-XGB which is XGB that uses all GPUs.</p>",
                          "votes": null,
                          "replies": [
                            {
                              "id": 2491425,
                              "author_name": "jjinho",
                              "author_url": "",
                              "post_date": "10/21/2023 15:52:27",
                              "content": "<p>Thanks for clarifying that and looking forward to seeing that demo.</p>",
                              "votes": null,
                              "replies": []
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "id": 2491492,
                      "author_name": "alejopaullier",
                      "author_url": "",
                      "post_date": "10/21/2023 17:00:22",
                      "content": "<p>Thanks <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> after concatenating all numpy arrays when training, do you use polars to convert the array into a dataframe?</p>",
                      "votes": null,
                      "replies": [
                        {
                          "id": 2491529,
                          "author_name": "cdeotte",
                          "author_url": "",
                          "post_date": "10/21/2023 17:25:56",
                          "content": "<p>No, i train directly with NumPy arrays.</p>",
                          "votes": null,
                          "replies": []
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "id": 2491487,
              "author_name": "alejopaullier",
              "author_url": "",
              "post_date": "10/21/2023 16:53:15",
              "content": "<p>By any chance has anyone taken the time to make a train dataset with the correct timestamp or at least slices? I used Andrada’s but the timestamps are wrong. I had to refactor all my code</p>",
              "votes": null,
              "replies": [
                {
                  "id": 2491555,
                  "author_name": "jjinho",
                  "author_url": "",
                  "post_date": "10/21/2023 17:47:04",
                  "content": "<p>I saved the outputs here: <a href=\"https://www.kaggle.com/code/jjinho/simple-utc-conversion-using-polars\" target=\"_blank\">https://www.kaggle.com/code/jjinho/simple-utc-conversion-using-polars</a></p>",
                  "votes": null,
                  "replies": []
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2490458": "ryanholbrook could you check if there are still data inconsistencies after the data update? For instance, I found for series `2f7504d0f426` that there is 1 hour missing between steps `200879` and `200880`:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3197853%2Fb338eb4a93e0a38e605baba4616f14e3%2FScreen%20Shot%202023-10-20%20at%2014.26.21.png?generation=1697822938043936&alt=media)\n\nThanks :)",
    "2490469": "I was going to suggest that was when daylight saving time switched over (it's at 2am in the Spring, so losing an hour), but Google says Daylight savings time in 2018 was on March 11, not March 18. yes, odd.",
    "2490500": "Some other weird series: \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3197853%2F0f0b1e571e2da57c74fe18537bbd726c%2FScreen%20Shot%202023-10-20%20at%2015.10.51.png?generation=1697825480730381&alt=media)\n\nThis one goes back and forth in time.",
    "2490509": "I think that data should be checked for consecutive jumps of 5 seconds. If not, the data is wrong",
    "2490514": "So that one matches with daylight savings time ending in 2018, but is also a week off (It was Nov 4, not Nov 11 that year). So it looks like the data could be all a week off?",
    "2490551": "I truly don't know, but I have found numerous cases where there's either data missing or these \"back in time\" cases",
    "2490626": "There is no time missing. Row 25209359 is 1:59:55 and timezone UTC-5. Then the next row 25209360 is 3:00:00 and timezone UTC-4. If we convert both to UTC time zone, then the first is 6:59:55 and the second is 7:00:00\n\nWhen converting this column from string to datetime, we need to convert everything to the same timezone. I have confirmed that the entire train data has 5 second gap between every consecutive row.",
    "2490690": "Thanks Chris, I am using datetime’s strptime method. Maybe its an issue with this conversion method. Which one are you using?",
    "2491092": "Perhaps they crossed a timezone border?",
    "2491341": "I'm using `cudf.to_datetime()` which converts everything to UTC timezone (and afterward every row is 5 seconds difference). I've noticed that the `pd.to_datetime()` does not convert everything to the same timezone. Pandas keeps the original timezones.\n\nWith Pandas we can do the following to cast all times to UTC timezone. Then we will see no gaps in `df.timestamp.dt.hour`:\n\n    import pytz\n    default_datetime = \"1970-01-01T00:00:00+0000\"\n    df['timestamp'] = df['timestamp'].fillna(default_datetime)\n    df['timestamp'] = pd.to_datetime(df['timestamp'], format='%Y-%m-%dT%H:%M:%S%z')\n    df['timestamp'] = df['timestamp'].apply(lambda x: x.astimezone(pytz.utc))\n    df.loc[df.timestamp.dt.year==1970,'timestamp'] = pd.NaT",
    "2491345": "moth: There is a Daylight Time Saving (DTS) change labelling issue in the timestamps of the raw dataset. It is the root cause of what you see (and, yes, it does not manifest if you cast the timestamps to UTC). You may follow the notebook per https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check  for the full assessment/analysis of this problem.",
    "2491348": "chris62 , @alejopaullier : yes, the root cause of this issue is the wrong DST change date used in the raw dataset. You can https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check for more detailed analysis of the glitch.",
    "2491350": "fritzcremer : yes, crossing the DST change  dates (along with the wrong DST change dates used in the raw timestamps) is the reason for the issues observed. I posted the  link to my notebook with the detailed analysis of the problem in earlier comments to this thread.",
    "2491379": "Hi @alejopaullier, not sure if this is still an issue for you. However I tried using `cudf` as per @cdeotte but it runs out of memory on kaggle (I assume he's using his own hardware). However when loading the data using polars, adding `time_zone='UTC'` fixes this problem (as shown below):\n\n```\nimport polars as pl\n\ndt_transforms = [\n    pl.col('timestamp').str.to_datetime(time_zone='UTC'), \n    (pl.col('timestamp').str.to_datetime().dt.date()).alias('date'), \n    pl.col('timestamp').str.to_datetime().dt.time().alias('time')\n]\n\ntrn_series = (\n    pl.scan_parquet('/kaggle/input/child-mind-institute-detect-sleep-states/train_series.parquet')\n    .with_columns((dt_transforms))\n    .collect()\n    .to_pandas()\n)\n```\n\nAnd the results look like:\n![fixed series 3c336d6ba566](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F557179%2F8e04b6e820806ba60fe87b1c7ac880b1%2FScreenshot%202023-10-21%20at%2011.19.32%20AM.png?generation=1697901601310187&alt=media)\n\nThis also seems to be fairly fast and can be applied during submission.",
    "2491388": "jjinho The best way to use cuDF is to split the original parquet into 277 parquets (one per `series_id`) with code [here][1]. Afterward we load one `series_id` parquet at a time with cuDF, then create features, then save result to disk as NumPy, then clear memory. Then to train our model, we load all `series_id` NumPys and concatenate into train data.\n\n[1]: https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/447593",
    "2491393": "Thanks @cdeotte, that makes total sense. I missed that. And for future reference, when using cuDF, if we use the T4x2 environment, does it automatically divide data over both GPUs?",
    "2491417": "No, cuDF by itself will only use 1 GPU. To use 2xGPU, we need to use DASK-cuDF (which allows us to write code same as cuDF but behind the scenes DASK will utilize all GPU).\n\nOne of these days, i will publish a DASK demo. There is also DASK-XGB which is XGB that uses all GPUs.",
    "2491425": "Thanks for clarifying that and looking forward to seeing that demo.",
    "2491487": "By any chance has anyone taken the time to make a train dataset with the correct timestamp or at least slices? I used Andrada’s but the timestamps are wrong. I had to refactor all my code",
    "2491492": "Thanks @cdeotte after concatenating all numpy arrays when training, do you use polars to convert the array into a dataframe?",
    "2491529": "No, i train directly with NumPy arrays.",
    "2491555": "I saved the outputs here: https://www.kaggle.com/code/jjinho/simple-utc-conversion-using-polars"
  },
  "source": "meta"
}