{
  "id": 102856,
  "title": "How to detect overfitting with LightGBM?",
  "url": "/competitions/champs-scalar-coupling/discussion/102856",
  "author_name": "Samuel",
  "post_date": "2019-08-05T15:33:18.936000",
  "votes": 4,
  "comment_count": 16,
  "views": 0,
  "content": "<p>Hi!</p>\n\n<p>Looking for inspiration on what to try next, I saw that a lot of kernels were using LightGBM, so I decided to give it a try. I would like to know how you guys deal with overfitting. Specifically, how to detect that it's happening.</p>\n\n<p>For the time being, while I try different things out, I have the training data split into a training and a validation set. I thought that keeping an eye on the learning curves would give me a good feeling for the onset of overfitting. However, I get curves like this:</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2652652%2Ff5095b21f6ca0a215dd909c595226a2a%2FScreenshot%20from%202019-08-05%2017-22-05.png?generation=1565018712966033&amp;alt=media\" alt=\"\"></p>\n\n<p>...where the validation and training errors basically go hand in hand the whole time. My gut feeling is that after ~200 iterations, the model should start overfitting, but I don't see the validation error increasing. What do you think about this? What other methods do you use to detect overfitting?</p>",
  "messages": [
    {
      "id": 592630,
      "postDate": "2019-08-05T15:33:18.937Z",
      "content": "<p>Hi!</p>\n\n<p>Looking for inspiration on what to try next, I saw that a lot of kernels were using LightGBM, so I decided to give it a try. I would like to know how you guys deal with overfitting. Specifically, how to detect that it's happening.</p>\n\n<p>For the time being, while I try different things out, I have the training data split into a training and a validation set. I thought that keeping an eye on the learning curves would give me a good feeling for the onset of overfitting. However, I get curves like this:</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2652652%2Ff5095b21f6ca0a215dd909c595226a2a%2FScreenshot%20from%202019-08-05%2017-22-05.png?generation=1565018712966033&amp;alt=media\" alt=\"\"></p>\n\n<p>...where the validation and training errors basically go hand in hand the whole time. My gut feeling is that after ~200 iterations, the model should start overfitting, but I don't see the validation error increasing. What do you think about this? What other methods do you use to detect overfitting?</p>",
      "rawMarkdown": "Hi!\n\nLooking for inspiration on what to try next, I saw that a lot of kernels were using LightGBM, so I decided to give it a try. I would like to know how you guys deal with overfitting. Specifically, how to detect that it's happening.\n\nFor the time being, while I try different things out, I have the training data split into a training and a validation set. I thought that keeping an eye on the learning curves would give me a good feeling for the onset of overfitting. However, I get curves like this:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2652652%2Ff5095b21f6ca0a215dd909c595226a2a%2FScreenshot%20from%202019-08-05%2017-22-05.png?generation=1565018712966033&amp;alt=media)\n\n...where the validation and training errors basically go hand in hand the whole time. My gut feeling is that after ~200 iterations, the model should start overfitting, but I don't see the validation error increasing. What do you think about this? What other methods do you use to detect overfitting?",
      "votes": 4
    },
    {
      "id": 592764,
      "postDate": "2019-08-05T19:39:21.833Z",
      "content": "<p>If the validation error is still decreasing, then there is an argument to say that you are not overfitting.</p>",
      "rawMarkdown": "If the validation error is still decreasing, then there is an argument to say that you are not overfitting.",
      "votes": 1,
      "replies": [
        {
          "id": 593105,
          "postDate": "2019-08-06T07:33:00.197Z",
          "content": "<p>Yes, that's exactly what puzzles me! By that reasoning, the training is just not finished. But it's been thousands of iterations for very little improvement, compared to the huge drop in the first ~100. That's why I suspect overfitting rather than actual learning. Also, the submissions aren't anywhere near the score predicted by the validation results.</p>",
          "rawMarkdown": "Yes, that's exactly what puzzles me! By that reasoning, the training is just not finished. But it's been thousands of iterations for very little improvement, compared to the huge drop in the first ~100. That's why I suspect overfitting rather than actual learning. Also, the submissions aren't anywhere near the score predicted by the validation results."
        }
      ]
    },
    {
      "id": 592645,
      "postDate": "2019-08-05T15:57:19.237Z",
      "content": "<p>I am a newb so take it with some caution, but this looks like you are underfitting?  try to increase your max_depth or num_leaves?</p>",
      "rawMarkdown": "I am a newb so take it with some caution, but this looks like you are underfitting?  try to increase your max_depth or num_leaves?",
      "votes": 1,
      "replies": [
        {
          "id": 593102,
          "postDate": "2019-08-06T07:26:59.743Z",
          "content": "<p>Thanks, <a href=\"/proletheus\">@proletheus</a>! I'm also quite new at this, so I will double-check everything (: Why do you think it is underfitting? I would expect the MAE to remain high (&gt; 1) in this case. </p>\n\n<p>I tried your suggestion, to make sure I wasn't overlooking something. It doesn't seem to help (the score improves a little, but I think the overfitting is just even stronger). Also, during training LightGBM produces several warnings that there are no further splits with positive gain, so I guess that's as precise as it can get.</p>",
          "rawMarkdown": "Thanks, @proletheus! I'm also quite new at this, so I will double-check everything (: Why do you think it is underfitting? I would expect the MAE to remain high (&gt; 1) in this case. \n\nI tried your suggestion, to make sure I wasn't overlooking something. It doesn't seem to help (the score improves a little, but I think the overfitting is just even stronger). Also, during training LightGBM produces several warnings that there are no further splits with positive gain, so I guess that's as precise as it can get.",
          "votes": 1
        },
        {
          "id": 593197,
          "postDate": "2019-08-06T09:45:33.940Z",
          "content": "<p>but your training and validation error is pretty much the same? I assume overfitting means building a model that does too well on train data but fails to generalize on test/validation data. for yours its  the opposite, it performs the same on train/test, which might indicate it is not flexible enough to capture any meaningful relationships?</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3353913%2F84274976ceabab8210f25912b39cdfbf%2FScreenshot_2.png?generation=1565084709900227&amp;alt=media\" alt=\"\"></p>\n\n<p>i stole this from <a href=\"https://www.youtube.com/watch?v=VZuKBKd4ck4\">https://www.youtube.com/watch?v=VZuKBKd4ck4</a>. </p>",
          "rawMarkdown": "but your training and validation error is pretty much the same? I assume overfitting means building a model that does too well on train data but fails to generalize on test/validation data. for yours its  the opposite, it performs the same on train/test, which might indicate it is not flexible enough to capture any meaningful relationships?\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3353913%2F84274976ceabab8210f25912b39cdfbf%2FScreenshot_2.png?generation=1565084709900227&amp;alt=media)\n\n\ni stole this from https://www.youtube.com/watch?v=VZuKBKd4ck4. ",
          "votes": 1
        },
        {
          "id": 593535,
          "postDate": "2019-08-06T18:31:05.993Z",
          "content": "<p>I thought about it and I think that you are absolutely right. Like I commented <a href=\"https://www.kaggle.com/c/champs-scalar-coupling/discussion/102856#593531\">here</a>, I was distracted by the very long plateau without error improvement. Thanks!</p>",
          "rawMarkdown": "I thought about it and I think that you are absolutely right. Like I commented [here](https://www.kaggle.com/c/champs-scalar-coupling/discussion/102856#593531), I was distracted by the very long plateau without error improvement. Thanks!",
          "votes": 1
        }
      ]
    },
    {
      "id": 593270,
      "postDate": "2019-08-06T11:48:01.767Z",
      "content": "<p>\"My gut feeling is that after ~200 iterations, the model should start overfitting, but I don't see the validation error increasing.\"  </p>\n\n<p>What is this feeling based on?  I see no reason to believe that the model should start overfitting after 200 trees.  It's common to fit GBMs with <em>way</em> more trees than this.</p>",
      "rawMarkdown": "\"My gut feeling is that after ~200 iterations, the model should start overfitting, but I don't see the validation error increasing.\"  \n\nWhat is this feeling based on?  I see no reason to believe that the model should start overfitting after 200 trees.  It's common to fit GBMs with *way* more trees than this.\n\n",
      "votes": 2,
      "replies": [
        {
          "id": 593522,
          "postDate": "2019-08-06T18:12:32.643Z",
          "content": "<p>Good point. Two main reasons:\n- The sudden change in the learning speed. There is a lot happening in the first 200 iterations, and the next thousands only improve the error marginally.\n- The fact that the LB score is significantly worse than the validation score.</p>\n\n<p>However, reading all the comments is making me change my mind about that interpretation...</p>",
          "rawMarkdown": "Good point. Two main reasons:\n- The sudden change in the learning speed. There is a lot happening in the first 200 iterations, and the next thousands only improve the error marginally.\n- The fact that the LB score is significantly worse than the validation score.\n\nHowever, reading all the comments is making me change my mind about that interpretation...",
          "votes": 1
        },
        {
          "id": 593545,
          "postDate": "2019-08-06T19:06:32.177Z",
          "content": "<p>LB worse than validation score may be a different issue.  Are you using cross-validation?  If so, are you using GroupKFold by to ensure that rows for the same molecule all up in the same fold?</p>",
          "rawMarkdown": "LB worse than validation score may be a different issue.  Are you using cross-validation?  If so, are you using GroupKFold by to ensure that rows for the same molecule all up in the same fold?"
        },
        {
          "id": 593577,
          "postDate": "2019-08-06T20:33:16.453Z",
          "content": "<p>Aha, interesting! That makes sense, that probably is another issue. I'm not doing CV at the moment: I wanted to start with a simple train/test split to get a first feeling of how the model behaves. But thanks for mentioning it, I'll keep that in mind if I compare the results in the future!</p>",
          "rawMarkdown": "Aha, interesting! That makes sense, that probably is another issue. I'm not doing CV at the moment: I wanted to start with a simple train/test split to get a first feeling of how the model behaves. But thanks for mentioning it, I'll keep that in mind if I compare the results in the future!",
          "votes": 1
        }
      ]
    },
    {
      "id": 593330,
      "postDate": "2019-08-06T13:09:24.373Z",
      "content": "<p>The random split also goes a long way in detecting the overfitting.\nBayesian Optimization can help reduce it also</p>",
      "rawMarkdown": "The random split also goes a long way in detecting the overfitting.\nBayesian Optimization can help reduce it also",
      "replies": [
        {
          "id": 593580,
          "postDate": "2019-08-06T20:34:29.130Z",
          "content": "<p>Hey thanks for the input! I couldn't quite follow, could you elaborate? </p>",
          "rawMarkdown": "Hey thanks for the input! I couldn't quite follow, could you elaborate? "
        }
      ]
    },
    {
      "id": 592876,
      "postDate": "2019-08-05T23:54:55.710Z",
      "content": "<p>Hi! <a href=\"/lesamu\">@lesamu</a>, I will try to use some cross-validation, just to see how the training/validation performs</p>",
      "rawMarkdown": "Hi! @lesamu, I will try to use some cross-validation, just to see how the training/validation performs",
      "replies": [
        {
          "id": 593108,
          "postDate": "2019-08-06T07:36:12.410Z",
          "content": "<p>Thanks, I'll try that.</p>",
          "rawMarkdown": "Thanks, I'll try that."
        }
      ]
    },
    {
      "id": 593437,
      "postDate": "2019-08-06T15:48:29.280Z",
      "rawMarkdown": "",
      "votes": 1,
      "isDeleted": true,
      "replies": [
        {
          "id": 593531,
          "postDate": "2019-08-06T18:27:47.273Z",
          "content": "<p>Many thanks for the suggestion! That gives me some insight into what could be \"expected\". Reading the previous comments I decided to give it a try at 20.000 rounds / early stopping after 200. Most groups haven't triggered the early stopping by then! The graphs look like this:</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2652652%2F7856360c173044d337aee7f222bea371%2FScreenshot%20from%202019-08-06%2020-15-03.png?generation=1565115376399356&amp;alt=media\" alt=\"\"></p>\n\n<p>Reading the comments, I am more convinced now that this is rather a case of underfitting. Funny! I was just blown away by sudden change in learning speed and the incredibly long plateau with almost no error improvement. Also the fact that the score on the submissions was lower than the validation score made me suspicious.</p>\n\n<p>It's nice that you and the others took some time to share their ideas. In the beginning, these comments are super helpful to understand what is going on, it can be quite confusing at times.</p>",
          "rawMarkdown": "Many thanks for the suggestion! That gives me some insight into what could be \"expected\". Reading the previous comments I decided to give it a try at 20.000 rounds / early stopping after 200. Most groups haven't triggered the early stopping by then! The graphs look like this:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2652652%2F7856360c173044d337aee7f222bea371%2FScreenshot%20from%202019-08-06%2020-15-03.png?generation=1565115376399356&amp;alt=media)\n\nReading the comments, I am more convinced now that this is rather a case of underfitting. Funny! I was just blown away by sudden change in learning speed and the incredibly long plateau with almost no error improvement. Also the fact that the score on the submissions was lower than the validation score made me suspicious.\n\nIt's nice that you and the others took some time to share their ideas. In the beginning, these comments are super helpful to understand what is going on, it can be quite confusing at times.",
          "votes": 2
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 592764,
      "author_name": "CoreyJamesLevinson",
      "author_url": "",
      "post_date": "2019-08-05T19:39:21.833000",
      "content": "<p>If the validation error is still decreasing, then there is an argument to say that you are not overfitting.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 593105,
          "author_name": "Samuel",
          "author_url": "",
          "post_date": "2019-08-06T07:33:00.197000",
          "content": "<p>Yes, that's exactly what puzzles me! By that reasoning, the training is just not finished. But it's been thousands of iterations for very little improvement, compared to the huge drop in the first ~100. That's why I suspect overfitting rather than actual learning. Also, the submissions aren't anywhere near the score predicted by the validation results.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 592645,
      "author_name": "Proletheus",
      "author_url": "",
      "post_date": "2019-08-05T15:57:19.237000",
      "content": "<p>I am a newb so take it with some caution, but this looks like you are underfitting?  try to increase your max_depth or num_leaves?</p>",
      "votes": 1,
      "replies": [
        {
          "id": 593102,
          "author_name": "Samuel",
          "author_url": "",
          "post_date": "2019-08-06T07:26:59.743000",
          "content": "<p>Thanks, <a href=\"/proletheus\">@proletheus</a>! I'm also quite new at this, so I will double-check everything (: Why do you think it is underfitting? I would expect the MAE to remain high (&gt; 1) in this case. </p>\n\n<p>I tried your suggestion, to make sure I wasn't overlooking something. It doesn't seem to help (the score improves a little, but I think the overfitting is just even stronger). Also, during training LightGBM produces several warnings that there are no further splits with positive gain, so I guess that's as precise as it can get.</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 593197,
          "author_name": "Proletheus",
          "author_url": "",
          "post_date": "2019-08-06T09:45:33.940000",
          "content": "<p>but your training and validation error is pretty much the same? I assume overfitting means building a model that does too well on train data but fails to generalize on test/validation data. for yours its  the opposite, it performs the same on train/test, which might indicate it is not flexible enough to capture any meaningful relationships?</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F3353913%2F84274976ceabab8210f25912b39cdfbf%2FScreenshot_2.png?generation=1565084709900227&amp;alt=media\" alt=\"\"></p>\n\n<p>i stole this from <a href=\"https://www.youtube.com/watch?v=VZuKBKd4ck4\">https://www.youtube.com/watch?v=VZuKBKd4ck4</a>. </p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 593535,
          "author_name": "Samuel",
          "author_url": "",
          "post_date": "2019-08-06T18:31:05.993000",
          "content": "<p>I thought about it and I think that you are absolutely right. Like I commented <a href=\"https://www.kaggle.com/c/champs-scalar-coupling/discussion/102856#593531\">here</a>, I was distracted by the very long plateau without error improvement. Thanks!</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 593270,
      "author_name": "fafafa fafafafa",
      "author_url": "",
      "post_date": "2019-08-06T11:48:01.767000",
      "content": "<p>\"My gut feeling is that after ~200 iterations, the model should start overfitting, but I don't see the validation error increasing.\"  </p>\n\n<p>What is this feeling based on?  I see no reason to believe that the model should start overfitting after 200 trees.  It's common to fit GBMs with <em>way</em> more trees than this.</p>",
      "votes": 2,
      "replies": [
        {
          "id": 593522,
          "author_name": "Samuel",
          "author_url": "",
          "post_date": "2019-08-06T18:12:32.643000",
          "content": "<p>Good point. Two main reasons:\n- The sudden change in the learning speed. There is a lot happening in the first 200 iterations, and the next thousands only improve the error marginally.\n- The fact that the LB score is significantly worse than the validation score.</p>\n\n<p>However, reading all the comments is making me change my mind about that interpretation...</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 593545,
          "author_name": "fafafa fafafafa",
          "author_url": "",
          "post_date": "2019-08-06T19:06:32.177000",
          "content": "<p>LB worse than validation score may be a different issue.  Are you using cross-validation?  If so, are you using GroupKFold by to ensure that rows for the same molecule all up in the same fold?</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 593577,
          "author_name": "Samuel",
          "author_url": "",
          "post_date": "2019-08-06T20:33:16.453000",
          "content": "<p>Aha, interesting! That makes sense, that probably is another issue. I'm not doing CV at the moment: I wanted to start with a simple train/test split to get a first feeling of how the model behaves. But thanks for mentioning it, I'll keep that in mind if I compare the results in the future!</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 593330,
      "author_name": "Raheem Nasirudeen",
      "author_url": "",
      "post_date": "2019-08-06T13:09:24.373000",
      "content": "<p>The random split also goes a long way in detecting the overfitting.\nBayesian Optimization can help reduce it also</p>",
      "votes": 0,
      "replies": [
        {
          "id": 593580,
          "author_name": "Samuel",
          "author_url": "",
          "post_date": "2019-08-06T20:34:29.130000",
          "content": "<p>Hey thanks for the input! I couldn't quite follow, could you elaborate? </p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 592876,
      "author_name": "C4rl05/V",
      "author_url": "",
      "post_date": "2019-08-05T23:54:55.710000",
      "content": "<p>Hi! <a href=\"/lesamu\">@lesamu</a>, I will try to use some cross-validation, just to see how the training/validation performs</p>",
      "votes": 0,
      "replies": [
        {
          "id": 593108,
          "author_name": "Samuel",
          "author_url": "",
          "post_date": "2019-08-06T07:36:12.410000",
          "content": "<p>Thanks, I'll try that.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 593437,
      "author_name": "",
      "author_url": "",
      "post_date": "2019-08-06T15:48:29.280000",
      "content": "",
      "votes": 1,
      "replies": [
        {
          "id": 593531,
          "author_name": "Samuel",
          "author_url": "",
          "post_date": "2019-08-06T18:27:47.273000",
          "content": "<p>Many thanks for the suggestion! That gives me some insight into what could be \"expected\". Reading the previous comments I decided to give it a try at 20.000 rounds / early stopping after 200. Most groups haven't triggered the early stopping by then! The graphs look like this:</p>\n\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2652652%2F7856360c173044d337aee7f222bea371%2FScreenshot%20from%202019-08-06%2020-15-03.png?generation=1565115376399356&amp;alt=media\" alt=\"\"></p>\n\n<p>Reading the comments, I am more convinced now that this is rather a case of underfitting. Funny! I was just blown away by sudden change in learning speed and the incredibly long plateau with almost no error improvement. Also the fact that the score on the submissions was lower than the validation score made me suspicious.</p>\n\n<p>It's nice that you and the others took some time to share their ideas. In the beginning, these comments are super helpful to understand what is going on, it can be quite confusing at times.</p>",
          "votes": 2,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "592630": "Hi!\n\nLooking for inspiration on what to try next, I saw that a lot of kernels were using LightGBM, so I decided to give it a try. I would like to know how you guys deal with overfitting. Specifically, how to detect that it's happening.\n\nFor the time being, while I try different things out, I have the training data split into a training and a validation set. I thought that keeping an eye on the learning curves would give me a good feeling for the onset of overfitting. However, I get curves like this:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2652652%2Ff5095b21f6ca0a215dd909c595226a2a%2FScreenshot%20from%202019-08-05%2017-22-05.png?generation=1565018712966033&amp;alt=media)\n\n...where the validation and training errors basically go hand in hand the whole time. My gut feeling is that after ~200 iterations, the model should start overfitting, but I don't see the validation error increasing. What do you think about this? What other methods do you use to detect overfitting?",
    "592764": "If the validation error is still decreasing, then there is an argument to say that you are not overfitting.",
    "592645": "I am a newb so take it with some caution, but this looks like you are underfitting?  try to increase your max_depth or num_leaves?",
    "593270": "\"My gut feeling is that after ~200 iterations, the model should start overfitting, but I don't see the validation error increasing.\"  \n\nWhat is this feeling based on?  I see no reason to believe that the model should start overfitting after 200 trees.  It's common to fit GBMs with *way* more trees than this.\n\n",
    "593330": "The random split also goes a long way in detecting the overfitting.\nBayesian Optimization can help reduce it also",
    "592876": "Hi! @lesamu, I will try to use some cross-validation, just to see how the training/validation performs",
    "593437": ""
  }
}