{
  "id": 451388,
  "title": "Released a Starter Notebook - How to perform CV in this competition",
  "url": "/competitions/child-mind-institute-detect-sleep-states/discussion/451388",
  "author_name": "",
  "post_date": "2023-10-28T14:10:20.942350600Z",
  "votes": 17,
  "comment_count": 7,
  "views": 0,
  "content": "<p>I have realised that almost all the public notebooks do not perform cross validation (CV) of any kind. Based on my experience, writing a correct CV function itself is not as simple as other comps with basic metrics like MAE or RMSE</p>\n<p>Therefore, I am releasing a starter notebook with a working version of CV. <strong>In this example, it uses a 5-fold StratifiedGroupKFold with a single XGB model, based on the architecture of most high scoring GBT public notebooks</strong>. It can be modified to suit Polars or NN use cases.</p>\n<p>The notebook is available <a href=\"https://www.kaggle.com/code/yeoyunsianggeremie/how-to-perform-cv-gradient-boosting\" target=\"_blank\">here</a>. Please upvote if you liked it or find it helpful! If you have any questions, feel free to write them in the comments</p>",
  "messages": [
    {
      "id": "2502838",
      "postDate": "10/28/2023 14:10:20",
      "content": "<p>I have realised that almost all the public notebooks do not perform cross validation (CV) of any kind. Based on my experience, writing a correct CV function itself is not as simple as other comps with basic metrics like MAE or RMSE</p>\n<p>Therefore, I am releasing a starter notebook with a working version of CV. <strong>In this example, it uses a 5-fold StratifiedGroupKFold with a single XGB model, based on the architecture of most high scoring GBT public notebooks</strong>. It can be modified to suit Polars or NN use cases.</p>\n<p>The notebook is available <a href=\"https://www.kaggle.com/code/yeoyunsianggeremie/how-to-perform-cv-gradient-boosting\" target=\"_blank\">here</a>. Please upvote if you liked it or find it helpful! If you have any questions, feel free to write them in the comments</p>",
      "rawMarkdown": "I have realised that almost all the public notebooks do not perform cross validation (CV) of any kind. Based on my experience, writing a correct CV function itself is not as simple as other comps with basic metrics like MAE or RMSE\n\nTherefore, I am releasing a starter notebook with a working version of CV. **In this example, it uses a 5-fold StratifiedGroupKFold with a single XGB model, based on the architecture of most high scoring GBT public notebooks**. It can be modified to suit Polars or NN use cases.\n\nThe notebook is available [here](https://www.kaggle.com/code/yeoyunsianggeremie/how-to-perform-cv-gradient-boosting). Please upvote if you liked it or find it helpful! If you have any questions, feel free to write them in the comments",
      "votes": null
    },
    {
      "id": "2502985",
      "postDate": "10/28/2023 16:07:35",
      "content": "<p>Thanks, this is important for me to verify the local cv.</p>",
      "rawMarkdown": "Thanks, this is important for me to verify the local cv.",
      "votes": null
    },
    {
      "id": "2503524",
      "postDate": "10/29/2023 07:09:45",
      "content": "<p><a href=\"https://www.kaggle.com/yeoyunsianggeremie\" target=\"_blank\">@yeoyunsianggeremie</a> : thanks for sharing it; loved to see StratifiedGroupKFold  used in an instrumental way (this one is the optimal one for the datetime-aware feature sets).</p>\n<p>Just FYI -  there is another CV example (for lightgbm though) published recently , per <a href=\"https://www.kaggle.com/code/andreytikhomirov/feature-selection-cv\" target=\"_blank\">https://www.kaggle.com/code/andreytikhomirov/feature-selection-cv</a> </p>\n<p>Good luck in the contest!</p>",
      "rawMarkdown": "yeoyunsianggeremie : thanks for sharing it; loved to see StratifiedGroupKFold  used in an instrumental way (this one is the optimal one for the datetime-aware feature sets).\n\nJust FYI -  there is another CV example (for lightgbm though) published recently , per https://www.kaggle.com/code/andreytikhomirov/feature-selection-cv \n\nGood luck in the contest!",
      "votes": null
    },
    {
      "id": "2503551",
      "postDate": "10/29/2023 07:45:01",
      "content": "<p>I was wondering if you could help me understand the benefits of using StratifiedGroupKFold over just GroupKFold in this context? </p>\n<p>I'd love to know if there's any specific stratification criteria we're aiming for. Thanks!</p>",
      "rawMarkdown": "I was wondering if you could help me understand the benefits of using StratifiedGroupKFold over just GroupKFold in this context? \n\nI'd love to know if there's any specific stratification criteria we're aiming for. Thanks!",
      "votes": null
    },
    {
      "id": "2503561",
      "postDate": "10/29/2023 07:52:43",
      "content": "<p><a href=\"https://www.kaggle.com/illidan7\" target=\"_blank\">@illidan7</a> : as mentioned in <a href=\"https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.StratifiedGroupKFold.html\" target=\"_blank\">Scikit-Learn Documentation</a>,</p>\n<blockquote>\nThe difference between GroupKFold and StratifiedGroupKFold is that the former attempts to create balanced folds such that the number of distinct groups is approximately the same in each fold, whereas StratifiedGroupKFold attempts to create folds which preserve the percentage of samples for each class as much as possible given the constraint of non-overlapping groups between splits.\n</blockquote>\n<p>You can delve more into the matter by reviewing the nice blog posts below</p>\n<ul>\n<li><a href=\"https://towardsdatascience.com/stratified-k-fold-cross-validation-on-grouped-datasets-b3bca8f0f53e\" target=\"_blank\">https://towardsdatascience.com/stratified-k-fold-cross-validation-on-grouped-datasets-b3bca8f0f53e</a></li>\n<li><a href=\"https://medium.com/the-techlife/5-different-ways-to-cross-validate-your-data-376a79b7f205\" target=\"_blank\">https://medium.com/the-techlife/5-different-ways-to-cross-validate-your-data-376a79b7f205</a></li>\n<li>etc. (acutally, there is plenty of such posts available in Internet)</li>\n</ul>\n<p>I hope it is helpful.</p>",
      "rawMarkdown": "illidan7 : as mentioned in [Scikit-Learn Documentation](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.StratifiedGroupKFold.html),\n<blockquote>\nThe difference between GroupKFold and StratifiedGroupKFold is that the former attempts to create balanced folds such that the number of distinct groups is approximately the same in each fold, whereas StratifiedGroupKFold attempts to create folds which preserve the percentage of samples for each class as much as possible given the constraint of non-overlapping groups between splits.\n</blockquote>\n\nYou can delve more into the matter by reviewing the nice blog posts below\n- https://towardsdatascience.com/stratified-k-fold-cross-validation-on-grouped-datasets-b3bca8f0f53e\n- https://medium.com/the-techlife/5-different-ways-to-cross-validate-your-data-376a79b7f205\n- etc. (acutally, there is plenty of such posts available in Internet)\n\nI hope it is helpful.",
      "votes": null
    },
    {
      "id": "2503584",
      "postDate": "10/29/2023 08:18:47",
      "content": "<p>The other CV example uses the accuracy metric which is very different from the competition metric</p>",
      "rawMarkdown": "The other CV example uses the accuracy metric which is very different from the competition metric",
      "votes": null
    },
    {
      "id": "2504542",
      "postDate": "10/30/2023 01:21:06",
      "content": "<p>Thanks for sharing, I took your work and made this <a href=\"https://www.kaggle.com/code/renatoreggiani/zzzs-how-to-optimize-models\" target=\"_blank\">notebook</a> to optimize the hyper-parameters of the models</p>",
      "rawMarkdown": "Thanks for sharing, I took your work and made this [notebook](https://www.kaggle.com/code/renatoreggiani/zzzs-how-to-optimize-models) to optimize the hyper-parameters of the models",
      "votes": null
    },
    {
      "id": "2505087",
      "postDate": "10/30/2023 11:05:45",
      "content": "<p>Thank you.</p>",
      "rawMarkdown": "Thank you.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2502985,
      "author_name": "gentlezdh",
      "author_url": "",
      "post_date": "10/28/2023 16:07:35",
      "content": "<p>Thanks, this is important for me to verify the local cv.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 2503524,
      "author_name": "gvyshnya",
      "author_url": "",
      "post_date": "10/29/2023 07:09:45",
      "content": "<p><a href=\"https://www.kaggle.com/yeoyunsianggeremie\" target=\"_blank\">@yeoyunsianggeremie</a> : thanks for sharing it; loved to see StratifiedGroupKFold  used in an instrumental way (this one is the optimal one for the datetime-aware feature sets).</p>\n<p>Just FYI -  there is another CV example (for lightgbm though) published recently , per <a href=\"https://www.kaggle.com/code/andreytikhomirov/feature-selection-cv\" target=\"_blank\">https://www.kaggle.com/code/andreytikhomirov/feature-selection-cv</a> </p>\n<p>Good luck in the contest!</p>",
      "votes": null,
      "replies": [
        {
          "id": 2503584,
          "author_name": "yeoyunsianggeremie",
          "author_url": "",
          "post_date": "10/29/2023 08:18:47",
          "content": "<p>The other CV example uses the accuracy metric which is very different from the competition metric</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2503551,
      "author_name": "illidan7",
      "author_url": "",
      "post_date": "10/29/2023 07:45:01",
      "content": "<p>I was wondering if you could help me understand the benefits of using StratifiedGroupKFold over just GroupKFold in this context? </p>\n<p>I'd love to know if there's any specific stratification criteria we're aiming for. Thanks!</p>",
      "votes": null,
      "replies": [
        {
          "id": 2503561,
          "author_name": "gvyshnya",
          "author_url": "",
          "post_date": "10/29/2023 07:52:43",
          "content": "<p><a href=\"https://www.kaggle.com/illidan7\" target=\"_blank\">@illidan7</a> : as mentioned in <a href=\"https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.StratifiedGroupKFold.html\" target=\"_blank\">Scikit-Learn Documentation</a>,</p>\n<blockquote>\nThe difference between GroupKFold and StratifiedGroupKFold is that the former attempts to create balanced folds such that the number of distinct groups is approximately the same in each fold, whereas StratifiedGroupKFold attempts to create folds which preserve the percentage of samples for each class as much as possible given the constraint of non-overlapping groups between splits.\n</blockquote>\n<p>You can delve more into the matter by reviewing the nice blog posts below</p>\n<ul>\n<li><a href=\"https://towardsdatascience.com/stratified-k-fold-cross-validation-on-grouped-datasets-b3bca8f0f53e\" target=\"_blank\">https://towardsdatascience.com/stratified-k-fold-cross-validation-on-grouped-datasets-b3bca8f0f53e</a></li>\n<li><a href=\"https://medium.com/the-techlife/5-different-ways-to-cross-validate-your-data-376a79b7f205\" target=\"_blank\">https://medium.com/the-techlife/5-different-ways-to-cross-validate-your-data-376a79b7f205</a></li>\n<li>etc. (acutally, there is plenty of such posts available in Internet)</li>\n</ul>\n<p>I hope it is helpful.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2504542,
      "author_name": "renatoreggiani",
      "author_url": "",
      "post_date": "10/30/2023 01:21:06",
      "content": "<p>Thanks for sharing, I took your work and made this <a href=\"https://www.kaggle.com/code/renatoreggiani/zzzs-how-to-optimize-models\" target=\"_blank\">notebook</a> to optimize the hyper-parameters of the models</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 2505087,
      "author_name": "dongyk",
      "author_url": "",
      "post_date": "10/30/2023 11:05:45",
      "content": "<p>Thank you.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2502838": "I have realised that almost all the public notebooks do not perform cross validation (CV) of any kind. Based on my experience, writing a correct CV function itself is not as simple as other comps with basic metrics like MAE or RMSE\n\nTherefore, I am releasing a starter notebook with a working version of CV. **In this example, it uses a 5-fold StratifiedGroupKFold with a single XGB model, based on the architecture of most high scoring GBT public notebooks**. It can be modified to suit Polars or NN use cases.\n\nThe notebook is available [here](https://www.kaggle.com/code/yeoyunsianggeremie/how-to-perform-cv-gradient-boosting). Please upvote if you liked it or find it helpful! If you have any questions, feel free to write them in the comments",
    "2502985": "Thanks, this is important for me to verify the local cv.",
    "2503524": "yeoyunsianggeremie : thanks for sharing it; loved to see StratifiedGroupKFold  used in an instrumental way (this one is the optimal one for the datetime-aware feature sets).\n\nJust FYI -  there is another CV example (for lightgbm though) published recently , per https://www.kaggle.com/code/andreytikhomirov/feature-selection-cv \n\nGood luck in the contest!",
    "2503551": "I was wondering if you could help me understand the benefits of using StratifiedGroupKFold over just GroupKFold in this context? \n\nI'd love to know if there's any specific stratification criteria we're aiming for. Thanks!",
    "2503561": "illidan7 : as mentioned in [Scikit-Learn Documentation](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.StratifiedGroupKFold.html),\n<blockquote>\nThe difference between GroupKFold and StratifiedGroupKFold is that the former attempts to create balanced folds such that the number of distinct groups is approximately the same in each fold, whereas StratifiedGroupKFold attempts to create folds which preserve the percentage of samples for each class as much as possible given the constraint of non-overlapping groups between splits.\n</blockquote>\n\nYou can delve more into the matter by reviewing the nice blog posts below\n- https://towardsdatascience.com/stratified-k-fold-cross-validation-on-grouped-datasets-b3bca8f0f53e\n- https://medium.com/the-techlife/5-different-ways-to-cross-validate-your-data-376a79b7f205\n- etc. (acutally, there is plenty of such posts available in Internet)\n\nI hope it is helpful.",
    "2503584": "The other CV example uses the accuracy metric which is very different from the competition metric",
    "2504542": "Thanks for sharing, I took your work and made this [notebook](https://www.kaggle.com/code/renatoreggiani/zzzs-how-to-optimize-models) to optimize the hyper-parameters of the models",
    "2505087": "Thank you."
  },
  "source": "meta"
}