{
  "id": 114144,
  "title": "Cross validation strategy for feature engineering and feature selection",
  "url": "/competitions/ashrae-energy-prediction/discussion/114144",
  "author_name": "",
  "post_date": "2019-10-24T14:51:50.855332500Z",
  "votes": 13,
  "comment_count": 6,
  "views": 0,
  "content": "<p>I realize that there was leakeage training with 5 StratifiedKFold (builiding_id), can't use this schema for validation. I train with the first 8 month and predict the last 4 month and then for the test use all the training data with previous early stopping but the score was not good. Any idea on how to make a good cross validations strategy in this competition?\nCheers!</p>",
  "messages": [
    {
      "id": "656708",
      "postDate": "10/24/2019 14:51:50",
      "content": "<p>I realize that there was leakeage training with 5 StratifiedKFold (builiding_id), can't use this schema for validation. I train with the first 8 month and predict the last 4 month and then for the test use all the training data with previous early stopping but the score was not good. Any idea on how to make a good cross validations strategy in this competition?\nCheers!</p>",
      "rawMarkdown": "I realize that there was leakeage training with 5 StratifiedKFold (builiding_id), can't use this schema for validation. I train with the first 8 month and predict the last 4 month and then for the test use all the training data with previous early stopping but the score was not good. Any idea on how to make a good cross validations strategy in this competition?\nCheers!",
      "votes": null
    },
    {
      "id": "656937",
      "postDate": "10/24/2019 19:19:35",
      "content": "<p>Hi <a href=\"/ragnar123\">@ragnar123</a> , I tried TimeSeriesSplit CV but I hadn't reliable results. I think that is mainly due to the fact that building ids ratio was not the same...</p>\n\n<p>As you said, StratifiedKFold easily gets temporal leakage. I think we should implement something in between, probably we could lose some data to get a stratified validation divided by time. Did someone try something like that?</p>",
      "rawMarkdown": "Hi @ragnar123 , I tried TimeSeriesSplit CV but I hadn't reliable results. I think that is mainly due to the fact that building ids ratio was not the same...\n\nAs you said, StratifiedKFold easily gets temporal leakage. I think we should implement something in between, probably we could lose some data to get a stratified validation divided by time. Did someone try something like that?",
      "votes": null
    },
    {
      "id": "657013",
      "postDate": "10/24/2019 20:56:28",
      "content": "<p>Maybee try  a groupkfold with 4 folds by quarter..... i will try other ideas and if i have a good result i will share it here</p>\n\n<p>Recently i made some feature selection and feature engineering with the following schema:</p>\n\n<p>Train with the first 8 month and then evaluate with the last 4 month</p>\n\n<p>Then i pick those features and for predicting the test i use 5 StratifiedKFold (builiding_id) but i manually put 1000 boosting rounds to avoid offerfitting. </p>\n\n<p>I want to check if the avaluation strategy align with the test, in other words if my eval with the 8/4 improve, also my test improve training with 5 StratifiedKFold with the features i selected in the 8/4 schema.</p>",
      "rawMarkdown": "Maybee try  a groupkfold with 4 folds by quarter..... i will try other ideas and if i have a good result i will share it here\n\nRecently i made some feature selection and feature engineering with the following schema:\n\nTrain with the first 8 month and then evaluate with the last 4 month\n\nThen i pick those features and for predicting the test i use 5 StratifiedKFold (builiding_id) but i manually put 1000 boosting rounds to avoid offerfitting. \n\nI want to check if the avaluation strategy align with the test, in other words if my eval with the 8/4 improve, also my test improve training with 5 StratifiedKFold with the features i selected in the 8/4 schema.",
      "votes": null
    },
    {
      "id": "657021",
      "postDate": "10/24/2019 21:07:43",
      "content": "<p>The fact is using just a time-based split doesn't guarantee you having all building ids in both training and validation sets. Then, I think GroupKFold on quarter doesn't prevent time leakage too cause. <a href=\"https://scikit-learn.org/stable/auto_examples/model_selection/plot_cv_indices.html#sphx-glr-auto-examples-model-selection-plot-cv-indices-py\">Good link to visualize CV methods</a>.</p>\n\n<p>I'm not sure about predicting using a different method from training. Isn't that like forcing different train and test distributions?</p>",
      "rawMarkdown": "The fact is using just a time-based split doesn't guarantee you having all building ids in both training and validation sets. Then, I think GroupKFold on quarter doesn't prevent time leakage too cause. [Good link to visualize CV methods](https://scikit-learn.org/stable/auto_examples/model_selection/plot_cv_indices.html#sphx-glr-auto-examples-model-selection-plot-cv-indices-py).\n\nI'm not sure about predicting using a different method from training. Isn't that like forcing different train and test distributions?",
      "votes": null
    },
    {
      "id": "657730",
      "postDate": "10/25/2019 11:51:47",
      "content": "<p>I tried my strategy but it failed. In my validation schema month was a very important feature but for predicting the test it overfitts big time. Maybee the the validation schema that we are looking for is just using the leader board  because the test and train have very different distributions. In other words no local validation strategy to do feature engineering and feature selection, just use the lb.</p>",
      "rawMarkdown": "I tried my strategy but it failed. In my validation schema month was a very important feature but for predicting the test it overfitts big time. Maybee the the validation schema that we are looking for is just using the leader board  because the test and train have very different distributions. In other words no local validation strategy to do feature engineering and feature selection, just use the lb.",
      "votes": null
    },
    {
      "id": "661435",
      "postDate": "10/30/2019 09:41:55",
      "content": "<p>To avoid data leakage in timeseries you should use  TimeSeriesSplit. The CV score will be worser than kfold, but will be closer to the test set/production. Just make sure to have enough data.\n<a href=\"https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html\">https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html</a>\n<a href=\"https://towardsdatascience.com/time-series-nested-cross-validation-76adba623eb9\">https://towardsdatascience.com/time-series-nested-cross-validation-76adba623eb9</a>\n<a href=\"https://conlanscientific.com/posts/category/blog/post/avoiding-data-leakage-machine-learning/\">https://conlanscientific.com/posts/category/blog/post/avoiding-data-leakage-machine-learning/</a></p>",
      "rawMarkdown": "To avoid data leakage in timeseries you should use  TimeSeriesSplit. The CV score will be worser than kfold, but will be closer to the test set/production. Just make sure to have enough data.\nhttps://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html\nhttps://towardsdatascience.com/time-series-nested-cross-validation-76adba623eb9\nhttps://conlanscientific.com/posts/category/blog/post/avoiding-data-leakage-machine-learning/",
      "votes": null
    },
    {
      "id": "665291",
      "postDate": "11/04/2019 21:18:21",
      "content": "<p>It is necessary to first order the data in time before use <code>TimeSeriesSplit</code>. It was noted that they may not be consistent in time in this competition.</p>",
      "rawMarkdown": "It is necessary to first order the data in time before use `TimeSeriesSplit`. It was noted that they may not be consistent in time in this competition.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 656937,
      "author_name": "raimonds1993",
      "author_url": "",
      "post_date": "10/24/2019 19:19:35",
      "content": "<p>Hi <a href=\"/ragnar123\">@ragnar123</a> , I tried TimeSeriesSplit CV but I hadn't reliable results. I think that is mainly due to the fact that building ids ratio was not the same...</p>\n\n<p>As you said, StratifiedKFold easily gets temporal leakage. I think we should implement something in between, probably we could lose some data to get a stratified validation divided by time. Did someone try something like that?</p>",
      "votes": null,
      "replies": [
        {
          "id": 657730,
          "author_name": "ragnar123",
          "author_url": "",
          "post_date": "10/25/2019 11:51:47",
          "content": "<p>I tried my strategy but it failed. In my validation schema month was a very important feature but for predicting the test it overfitts big time. Maybee the the validation schema that we are looking for is just using the leader board  because the test and train have very different distributions. In other words no local validation strategy to do feature engineering and feature selection, just use the lb.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 657013,
      "author_name": "ragnar123",
      "author_url": "",
      "post_date": "10/24/2019 20:56:28",
      "content": "<p>Maybee try  a groupkfold with 4 folds by quarter..... i will try other ideas and if i have a good result i will share it here</p>\n\n<p>Recently i made some feature selection and feature engineering with the following schema:</p>\n\n<p>Train with the first 8 month and then evaluate with the last 4 month</p>\n\n<p>Then i pick those features and for predicting the test i use 5 StratifiedKFold (builiding_id) but i manually put 1000 boosting rounds to avoid offerfitting. </p>\n\n<p>I want to check if the avaluation strategy align with the test, in other words if my eval with the 8/4 improve, also my test improve training with 5 StratifiedKFold with the features i selected in the 8/4 schema.</p>",
      "votes": null,
      "replies": [
        {
          "id": 657021,
          "author_name": "raimonds1993",
          "author_url": "",
          "post_date": "10/24/2019 21:07:43",
          "content": "<p>The fact is using just a time-based split doesn't guarantee you having all building ids in both training and validation sets. Then, I think GroupKFold on quarter doesn't prevent time leakage too cause. <a href=\"https://scikit-learn.org/stable/auto_examples/model_selection/plot_cv_indices.html#sphx-glr-auto-examples-model-selection-plot-cv-indices-py\">Good link to visualize CV methods</a>.</p>\n\n<p>I'm not sure about predicting using a different method from training. Isn't that like forcing different train and test distributions?</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 661435,
      "author_name": "hmavrodiev",
      "author_url": "",
      "post_date": "10/30/2019 09:41:55",
      "content": "<p>To avoid data leakage in timeseries you should use  TimeSeriesSplit. The CV score will be worser than kfold, but will be closer to the test set/production. Just make sure to have enough data.\n<a href=\"https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html\">https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html</a>\n<a href=\"https://towardsdatascience.com/time-series-nested-cross-validation-76adba623eb9\">https://towardsdatascience.com/time-series-nested-cross-validation-76adba623eb9</a>\n<a href=\"https://conlanscientific.com/posts/category/blog/post/avoiding-data-leakage-machine-learning/\">https://conlanscientific.com/posts/category/blog/post/avoiding-data-leakage-machine-learning/</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 665291,
      "author_name": "vbmokin",
      "author_url": "",
      "post_date": "11/04/2019 21:18:21",
      "content": "<p>It is necessary to first order the data in time before use <code>TimeSeriesSplit</code>. It was noted that they may not be consistent in time in this competition.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "656708": "I realize that there was leakeage training with 5 StratifiedKFold (builiding_id), can't use this schema for validation. I train with the first 8 month and predict the last 4 month and then for the test use all the training data with previous early stopping but the score was not good. Any idea on how to make a good cross validations strategy in this competition?\nCheers!",
    "656937": "Hi @ragnar123 , I tried TimeSeriesSplit CV but I hadn't reliable results. I think that is mainly due to the fact that building ids ratio was not the same...\n\nAs you said, StratifiedKFold easily gets temporal leakage. I think we should implement something in between, probably we could lose some data to get a stratified validation divided by time. Did someone try something like that?",
    "657013": "Maybee try  a groupkfold with 4 folds by quarter..... i will try other ideas and if i have a good result i will share it here\n\nRecently i made some feature selection and feature engineering with the following schema:\n\nTrain with the first 8 month and then evaluate with the last 4 month\n\nThen i pick those features and for predicting the test i use 5 StratifiedKFold (builiding_id) but i manually put 1000 boosting rounds to avoid offerfitting. \n\nI want to check if the avaluation strategy align with the test, in other words if my eval with the 8/4 improve, also my test improve training with 5 StratifiedKFold with the features i selected in the 8/4 schema.",
    "657021": "The fact is using just a time-based split doesn't guarantee you having all building ids in both training and validation sets. Then, I think GroupKFold on quarter doesn't prevent time leakage too cause. [Good link to visualize CV methods](https://scikit-learn.org/stable/auto_examples/model_selection/plot_cv_indices.html#sphx-glr-auto-examples-model-selection-plot-cv-indices-py).\n\nI'm not sure about predicting using a different method from training. Isn't that like forcing different train and test distributions?",
    "657730": "I tried my strategy but it failed. In my validation schema month was a very important feature but for predicting the test it overfitts big time. Maybee the the validation schema that we are looking for is just using the leader board  because the test and train have very different distributions. In other words no local validation strategy to do feature engineering and feature selection, just use the lb.",
    "661435": "To avoid data leakage in timeseries you should use  TimeSeriesSplit. The CV score will be worser than kfold, but will be closer to the test set/production. Just make sure to have enough data.\nhttps://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html\nhttps://towardsdatascience.com/time-series-nested-cross-validation-76adba623eb9\nhttps://conlanscientific.com/posts/category/blog/post/avoiding-data-leakage-machine-learning/",
    "665291": "It is necessary to first order the data in time before use `TimeSeriesSplit`. It was noted that they may not be consistent in time in this competition."
  },
  "source": "meta"
}