{
  "id": 453561,
  "title": "How do you deal with the test data preprocessing?",
  "url": "/competitions/child-mind-institute-detect-sleep-states/discussion/453561",
  "author_name": "",
  "post_date": "2023-11-06T21:14:39.982261Z",
  "votes": 1,
  "comment_count": 2,
  "views": 0,
  "content": "<p>I am currently using the train data. Loading it in this way:</p>\n<pre><code>data_dtype = {\n        : ,\n        : ,\n        : ,\n        : ,\n        : ,\n    }\n\ndata = pd.read_parquet().astype(data_dtype, copy=)\n</code></pre>\n<p>It works rather fast, takes about 4-5GB of the RAM.<br>\nThen I want to add some features, based on the timestamp, so I do this:</p>\n<pre><code>\ndata[] = pd.to_datetime(data[], utc=, cache=, =)\n</code></pre>\n<p>And this line works really long. Any ways to deal with it somehow? I want, for example, to add the hour of the day. I tried to load the data in the pandas first, then transfer it to the CUdf library, but it crashes due to memory error. I know that I can wait for some long time, then save preprocessed data in the pickle format. But I cannot do this with the test.</p>",
  "messages": [
    {
      "id": "2515325",
      "postDate": "11/06/2023 21:14:39",
      "content": "<p>I am currently using the train data. Loading it in this way:</p>\n<pre><code>data_dtype = {\n        : ,\n        : ,\n        : ,\n        : ,\n        : ,\n    }\n\ndata = pd.read_parquet().astype(data_dtype, copy=)\n</code></pre>\n<p>It works rather fast, takes about 4-5GB of the RAM.<br>\nThen I want to add some features, based on the timestamp, so I do this:</p>\n<pre><code>\ndata[] = pd.to_datetime(data[], utc=, cache=, =)\n</code></pre>\n<p>And this line works really long. Any ways to deal with it somehow? I want, for example, to add the hour of the day. I tried to load the data in the pandas first, then transfer it to the CUdf library, but it crashes due to memory error. I know that I can wait for some long time, then save preprocessed data in the pickle format. But I cannot do this with the test.</p>",
      "rawMarkdown": "I am currently using the train data. Loading it in this way:\n\n```python\ndata_dtype = {\n        \"series_id\": \"category\",\n        \"step\": \"uint32\",\n        \"timestamp\": \"str\",\n        \"anglez\": \"float32\",\n        \"enmo\": \"float32\",\n    }\n\ndata = pd.read_parquet(\"/kaggle/input/child-mind-institute-detect-sleep-states/train_series.parquet\").astype(data_dtype, copy=False)\n```\nIt works rather fast, takes about 4-5GB of the RAM.\nThen I want to add some features, based on the timestamp, so I do this:\n\n```python\n# Convert the timestamp column to Timestamp objects\ndata[\"timestamp_datetime\"] = pd.to_datetime(data[\"timestamp\"], utc=False, cache=True, format=\"%Y-%m-%dT%H:%M:%S-%f\")\n```\n\nAnd this line works really long. Any ways to deal with it somehow? I want, for example, to add the hour of the day. I tried to load the data in the pandas first, then transfer it to the CUdf library, but it crashes due to memory error. I know that I can wait for some long time, then save preprocessed data in the pickle format. But I cannot do this with the test.",
      "votes": null
    },
    {
      "id": "2515371",
      "postDate": "11/06/2023 22:10:23",
      "content": "<p><a href=\"https://www.kaggle.com/manwithaflower\" target=\"_blank\">@manwithaflower</a> : To tell the long story short, you can improve the performance of your data processing pipelines by </p>\n<ul>\n<li>doing the feature engineering in the batch mode, in a series-by-series manner</li>\n<li>reading data with some of the pandas alternatives that are more powerful when it comes to reading Big Data-scale datasets (Polar, Dask etc.)</li>\n</ul>\n<p>You can refer to <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/441047\" target=\"_blank\">Best Practices in Tackling BigData-Scale Tasks</a> to see the references to the specific examples of how it can be implemented (this thread is also useful if you like to see other tricks to improve the performance of your pipelines - for example, when you do the model training or/and prepare your submission from the test data).</p>\n<p>You can also review a few public notebooks where per-series feature engineering / data preprocessing adds the edge in terms of performance:</p>\n<ul>\n<li><a href=\"https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction\" target=\"_blank\">https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction</a></li>\n<li><a href=\"https://www.kaggle.com/code/siddhvr/cmi-ensembling-models-for-better-results\" target=\"_blank\">https://www.kaggle.com/code/siddhvr/cmi-ensembling-models-for-better-results</a></li>\n<li>etc.</li>\n</ul>\n<p>P. S. From the code fragment you  posted in your message, I noticed you attempt to convert the timestamp values to the datetime in the local time zone. You may want to refer to <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> to see the data quality-driven issues with such an approach (at the end, casting them to UTC may be a better idea to work around).</p>",
      "rawMarkdown": "manwithaflower : To tell the long story short, you can improve the performance of your data processing pipelines by \n\n- doing the feature engineering in the batch mode, in a series-by-series manner\n- reading data with some of the pandas alternatives that are more powerful when it comes to reading Big Data-scale datasets (Polar, Dask etc.)\n\nYou can refer to [Best Practices in Tackling BigData-Scale Tasks](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/441047) to see the references to the specific examples of how it can be implemented (this thread is also useful if you like to see other tricks to improve the performance of your pipelines - for example, when you do the model training or/and prepare your submission from the test data).\n\nYou can also review a few public notebooks where per-series feature engineering / data preprocessing adds the edge in terms of performance:\n\n- https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction\n- https://www.kaggle.com/code/siddhvr/cmi-ensembling-models-for-better-results\n- etc.\n\nP. S. From the code fragment you  posted in your message, I noticed you attempt to convert the timestamp values to the datetime in the local time zone. You may want to refer to https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check to see the data quality-driven issues with such an approach (at the end, casting them to UTC may be a better idea to work around).",
      "votes": null
    },
    {
      "id": "2515405",
      "postDate": "11/06/2023 23:10:05",
      "content": "<p>Aha, here it is! Thank you very much, finally I found the nice solution!</p>\n<p>This <a href=\"https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction\" target=\"_blank\">notebook</a> is really helpful. As I understood, we should load the series one by one by their id. And then we can do the feature engineering by id as well, using parallelization. Great!</p>",
      "rawMarkdown": "Aha, here it is! Thank you very much, finally I found the nice solution!\n\nThis [notebook](https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction) is really helpful. As I understood, we should load the series one by one by their id. And then we can do the feature engineering by id as well, using parallelization. Great!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2515371,
      "author_name": "gvyshnya",
      "author_url": "",
      "post_date": "11/06/2023 22:10:23",
      "content": "<p><a href=\"https://www.kaggle.com/manwithaflower\" target=\"_blank\">@manwithaflower</a> : To tell the long story short, you can improve the performance of your data processing pipelines by </p>\n<ul>\n<li>doing the feature engineering in the batch mode, in a series-by-series manner</li>\n<li>reading data with some of the pandas alternatives that are more powerful when it comes to reading Big Data-scale datasets (Polar, Dask etc.)</li>\n</ul>\n<p>You can refer to <a href=\"https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/441047\" target=\"_blank\">Best Practices in Tackling BigData-Scale Tasks</a> to see the references to the specific examples of how it can be implemented (this thread is also useful if you like to see other tricks to improve the performance of your pipelines - for example, when you do the model training or/and prepare your submission from the test data).</p>\n<p>You can also review a few public notebooks where per-series feature engineering / data preprocessing adds the edge in terms of performance:</p>\n<ul>\n<li><a href=\"https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction\" target=\"_blank\">https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction</a></li>\n<li><a href=\"https://www.kaggle.com/code/siddhvr/cmi-ensembling-models-for-better-results\" target=\"_blank\">https://www.kaggle.com/code/siddhvr/cmi-ensembling-models-for-better-results</a></li>\n<li>etc.</li>\n</ul>\n<p>P. S. From the code fragment you  posted in your message, I noticed you attempt to convert the timestamp values to the datetime in the local time zone. You may want to refer to <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> to see the data quality-driven issues with such an approach (at the end, casting them to UTC may be a better idea to work around).</p>",
      "votes": null,
      "replies": [
        {
          "id": 2515405,
          "author_name": "manwithaflower",
          "author_url": "",
          "post_date": "11/06/2023 23:10:05",
          "content": "<p>Aha, here it is! Thank you very much, finally I found the nice solution!</p>\n<p>This <a href=\"https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction\" target=\"_blank\">notebook</a> is really helpful. As I understood, we should load the series one by one by their id. And then we can do the feature engineering by id as well, using parallelization. Great!</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2515325": "I am currently using the train data. Loading it in this way:\n\n```python\ndata_dtype = {\n        \"series_id\": \"category\",\n        \"step\": \"uint32\",\n        \"timestamp\": \"str\",\n        \"anglez\": \"float32\",\n        \"enmo\": \"float32\",\n    }\n\ndata = pd.read_parquet(\"/kaggle/input/child-mind-institute-detect-sleep-states/train_series.parquet\").astype(data_dtype, copy=False)\n```\nIt works rather fast, takes about 4-5GB of the RAM.\nThen I want to add some features, based on the timestamp, so I do this:\n\n```python\n# Convert the timestamp column to Timestamp objects\ndata[\"timestamp_datetime\"] = pd.to_datetime(data[\"timestamp\"], utc=False, cache=True, format=\"%Y-%m-%dT%H:%M:%S-%f\")\n```\n\nAnd this line works really long. Any ways to deal with it somehow? I want, for example, to add the hour of the day. I tried to load the data in the pandas first, then transfer it to the CUdf library, but it crashes due to memory error. I know that I can wait for some long time, then save preprocessed data in the pickle format. But I cannot do this with the test.",
    "2515371": "manwithaflower : To tell the long story short, you can improve the performance of your data processing pipelines by \n\n- doing the feature engineering in the batch mode, in a series-by-series manner\n- reading data with some of the pandas alternatives that are more powerful when it comes to reading Big Data-scale datasets (Polar, Dask etc.)\n\nYou can refer to [Best Practices in Tackling BigData-Scale Tasks](https://www.kaggle.com/competitions/child-mind-institute-detect-sleep-states/discussion/441047) to see the references to the specific examples of how it can be implemented (this thread is also useful if you like to see other tricks to improve the performance of your pipelines - for example, when you do the model training or/and prepare your submission from the test data).\n\nYou can also review a few public notebooks where per-series feature engineering / data preprocessing adds the edge in terms of performance:\n\n- https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction\n- https://www.kaggle.com/code/siddhvr/cmi-ensembling-models-for-better-results\n- etc.\n\nP. S. From the code fragment you  posted in your message, I noticed you attempt to convert the timestamp values to the datetime in the local time zone. You may want to refer to https://www.kaggle.com/code/gvyshnya/sleeping-series-integrity-check to see the data quality-driven issues with such an approach (at the end, casting them to UTC may be a better idea to work around).",
    "2515405": "Aha, here it is! Thank you very much, finally I found the nice solution!\n\nThis [notebook](https://www.kaggle.com/code/lccburk/feature-engineering-and-random-forest-prediction) is really helpful. As I understood, we should load the series one by one by their id. And then we can do the feature engineering by id as well, using parallelization. Great!"
  },
  "source": "meta"
}