{
  "id": 475095,
  "title": "How to deal with imbalance data ? ",
  "url": "/competitions/home-credit-credit-risk-model-stability/discussion/475095",
  "author_name": "",
  "post_date": "2024-02-07T04:08:52.420531100Z",
  "votes": 19,
  "comment_count": 10,
  "views": 0,
  "content": "<p>Hi. I'm trying to deal with imbalance data in this competition.<br>\nAs you know, the dataset of this competition is imbalanced in target like following.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F6165188%2F1d822c81b263406552ecdcd5908849f2%2F__results___11_0.png?generation=1707278808913615&amp;alt=media\"><br>\nI will use three way to deal with imbalance data.</p>\n<ol>\n<li>FocalLoss for objective function in LGBMClassifier</li>\n<li>sample_weight : 'balanced' option in LGBMClassifier</li>\n<li>StratifiedKFold to balance positive and negative ratio of target.</li>\n</ol>\n<p>If you have any idea and information, Please comment and help !!!!  </p>\n<p>Histgram and circle picture is cited from here<br>\n<a href=\"https://www.kaggle.com/code/akhiljethwa/homecredit-basic-data-exploration\" target=\"_blank\">https://www.kaggle.com/code/akhiljethwa/homecredit-basic-data-exploration</a></p>",
  "messages": [
    {
      "id": "2640727",
      "postDate": "02/07/2024 04:08:52",
      "content": "<p>Hi. I'm trying to deal with imbalance data in this competition.<br>\nAs you know, the dataset of this competition is imbalanced in target like following.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F6165188%2F1d822c81b263406552ecdcd5908849f2%2F__results___11_0.png?generation=1707278808913615&amp;alt=media\"><br>\nI will use three way to deal with imbalance data.</p>\n<ol>\n<li>FocalLoss for objective function in LGBMClassifier</li>\n<li>sample_weight : 'balanced' option in LGBMClassifier</li>\n<li>StratifiedKFold to balance positive and negative ratio of target.</li>\n</ol>\n<p>If you have any idea and information, Please comment and help !!!!  </p>\n<p>Histgram and circle picture is cited from here<br>\n<a href=\"https://www.kaggle.com/code/akhiljethwa/homecredit-basic-data-exploration\" target=\"_blank\">https://www.kaggle.com/code/akhiljethwa/homecredit-basic-data-exploration</a></p>",
      "rawMarkdown": "Hi. I'm trying to deal with imbalance data in this competition.\nAs you know, the dataset of this competition is imbalanced in target like following.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F6165188%2F1d822c81b263406552ecdcd5908849f2%2F__results___11_0.png?generation=1707278808913615&alt=media)\nI will use three way to deal with imbalance data.\n1. FocalLoss for objective function in LGBMClassifier\n2. sample_weight : 'balanced' option in LGBMClassifier\n3. StratifiedKFold to balance positive and negative ratio of target.\n\nIf you have any idea and information, Please comment and help !!!!  \n\nHistgram and circle picture is cited from here\nhttps://www.kaggle.com/code/akhiljethwa/homecredit-basic-data-exploration",
      "votes": null
    },
    {
      "id": "2640859",
      "postDate": "02/07/2024 05:41:30",
      "content": "<p>For Xgboost there is the <code>scale_pos_weight</code> parameter or you can add <code>class_weights</code> when constructing the Dmatrix.<br>\nIn case you use target encoding you could tune the <code>smoothing</code> parameter.</p>",
      "rawMarkdown": "For Xgboost there is the `scale_pos_weight` parameter or you can add `class_weights` when constructing the Dmatrix.\nIn case you use target encoding you could tune the `smoothing` parameter.",
      "votes": null
    },
    {
      "id": "2640942",
      "postDate": "02/07/2024 07:07:28",
      "content": "<p>How it is a problem here? </p>",
      "rawMarkdown": "How it is a problem here?",
      "votes": null
    },
    {
      "id": "2641263",
      "postDate": "02/07/2024 11:29:42",
      "content": "<p>I'm using StratifiedKFold (5 folds).</p>",
      "rawMarkdown": "I'm using StratifiedKFold (5 folds).",
      "votes": null
    },
    {
      "id": "2642150",
      "postDate": "02/08/2024 00:47:14",
      "content": "<p>I think predicting positive(target 1 in home credit) will be difficult if it is.</p>",
      "rawMarkdown": "I think predicting positive(target 1 in home credit) will be difficult if it is.",
      "votes": null
    },
    {
      "id": "2642151",
      "postDate": "02/08/2024 00:47:47",
      "content": "<p>Thank u for your knowledge!</p>",
      "rawMarkdown": "Thank u for your knowledge!",
      "votes": null
    },
    {
      "id": "2642155",
      "postDate": "02/08/2024 00:52:04",
      "content": "<p>The problem and difficulty of imbalanced data is explained here.</p>\n<p><a href=\"https://machinelearningmastery.com/imbalanced-classification-is-hard/\" target=\"_blank\">https://machinelearningmastery.com/imbalanced-classification-is-hard/</a></p>",
      "rawMarkdown": "The problem and difficulty of imbalanced data is explained here.\n\nhttps://machinelearningmastery.com/imbalanced-classification-is-hard/",
      "votes": null
    },
    {
      "id": "2644508",
      "postDate": "02/09/2024 14:45:03",
      "content": "<p>thank you for your great experience!</p>",
      "rawMarkdown": "thank you for your great experience!",
      "votes": null
    },
    {
      "id": "2670490",
      "postDate": "02/26/2024 22:17:25",
      "content": "<p>I have recently posted a summary \"<a href=\"https://www.kaggle.com/competitions/home-credit-credit-risk-model-stability/discussion/478094\" target=\"_blank\">Improving model performance by handling data imbalance</a>\" as to how imbalance can be handled in XGboost, LightGBM and CatBoost. At the end of the post there are also a few references from previous imbalanced Kaggle competitions. Hope it could be of a help, <a href=\"https://www.kaggle.com/takumimukaiyama\" target=\"_blank\">@takumimukaiyama</a>.</p>",
      "rawMarkdown": "I have recently posted a summary \"[Improving model performance by handling data imbalance](https://www.kaggle.com/competitions/home-credit-credit-risk-model-stability/discussion/478094)\" as to how imbalance can be handled in XGboost, LightGBM and CatBoost. At the end of the post there are also a few references from previous imbalanced Kaggle competitions. Hope it could be of a help, @takumimukaiyama.",
      "votes": null
    },
    {
      "id": "2671108",
      "postDate": "02/27/2024 09:43:38",
      "content": "<p>For Xgboost you can also pass class weights during the Dmatrix creation. Could be worth testing.</p>",
      "rawMarkdown": "For Xgboost you can also pass class weights during the Dmatrix creation. Could be worth testing.",
      "votes": null
    },
    {
      "id": "2671294",
      "postDate": "02/27/2024 12:31:01",
      "content": "<p>Thanks, yes, I missed that. Will look through the source code to see if it is doing the same thing as weights passed to <code>XGBoost</code> constructor, and will update my post accordingly.</p>",
      "rawMarkdown": "Thanks, yes, I missed that. Will look through the source code to see if it is doing the same thing as weights passed to `XGBoost` constructor, and will update my post accordingly.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2640859,
      "author_name": "thomasmeiner",
      "author_url": "",
      "post_date": "02/07/2024 05:41:30",
      "content": "<p>For Xgboost there is the <code>scale_pos_weight</code> parameter or you can add <code>class_weights</code> when constructing the Dmatrix.<br>\nIn case you use target encoding you could tune the <code>smoothing</code> parameter.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2644508,
          "author_name": "takumimukaiyama",
          "author_url": "",
          "post_date": "02/09/2024 14:45:03",
          "content": "<p>thank you for your great experience!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2640942,
      "author_name": "lucasmorin",
      "author_url": "",
      "post_date": "02/07/2024 07:07:28",
      "content": "<p>How it is a problem here? </p>",
      "votes": null,
      "replies": [
        {
          "id": 2642150,
          "author_name": "takumimukaiyama",
          "author_url": "",
          "post_date": "02/08/2024 00:47:14",
          "content": "<p>I think predicting positive(target 1 in home credit) will be difficult if it is.</p>",
          "votes": null,
          "replies": [
            {
              "id": 2642155,
              "author_name": "takumimukaiyama",
              "author_url": "",
              "post_date": "02/08/2024 00:52:04",
              "content": "<p>The problem and difficulty of imbalanced data is explained here.</p>\n<p><a href=\"https://machinelearningmastery.com/imbalanced-classification-is-hard/\" target=\"_blank\">https://machinelearningmastery.com/imbalanced-classification-is-hard/</a></p>",
              "votes": null,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2641263,
      "author_name": "bratkovskyevgeny",
      "author_url": "",
      "post_date": "02/07/2024 11:29:42",
      "content": "<p>I'm using StratifiedKFold (5 folds).</p>",
      "votes": null,
      "replies": [
        {
          "id": 2642151,
          "author_name": "takumimukaiyama",
          "author_url": "",
          "post_date": "02/08/2024 00:47:47",
          "content": "<p>Thank u for your knowledge!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 2670490,
      "author_name": "kononenko",
      "author_url": "",
      "post_date": "02/26/2024 22:17:25",
      "content": "<p>I have recently posted a summary \"<a href=\"https://www.kaggle.com/competitions/home-credit-credit-risk-model-stability/discussion/478094\" target=\"_blank\">Improving model performance by handling data imbalance</a>\" as to how imbalance can be handled in XGboost, LightGBM and CatBoost. At the end of the post there are also a few references from previous imbalanced Kaggle competitions. Hope it could be of a help, <a href=\"https://www.kaggle.com/takumimukaiyama\" target=\"_blank\">@takumimukaiyama</a>.</p>",
      "votes": null,
      "replies": [
        {
          "id": 2671108,
          "author_name": "thomasmeiner",
          "author_url": "",
          "post_date": "02/27/2024 09:43:38",
          "content": "<p>For Xgboost you can also pass class weights during the Dmatrix creation. Could be worth testing.</p>",
          "votes": null,
          "replies": [
            {
              "id": 2671294,
              "author_name": "kononenko",
              "author_url": "",
              "post_date": "02/27/2024 12:31:01",
              "content": "<p>Thanks, yes, I missed that. Will look through the source code to see if it is doing the same thing as weights passed to <code>XGBoost</code> constructor, and will update my post accordingly.</p>",
              "votes": null,
              "replies": []
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2640727": "Hi. I'm trying to deal with imbalance data in this competition.\nAs you know, the dataset of this competition is imbalanced in target like following.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F6165188%2F1d822c81b263406552ecdcd5908849f2%2F__results___11_0.png?generation=1707278808913615&alt=media)\nI will use three way to deal with imbalance data.\n1. FocalLoss for objective function in LGBMClassifier\n2. sample_weight : 'balanced' option in LGBMClassifier\n3. StratifiedKFold to balance positive and negative ratio of target.\n\nIf you have any idea and information, Please comment and help !!!!  \n\nHistgram and circle picture is cited from here\nhttps://www.kaggle.com/code/akhiljethwa/homecredit-basic-data-exploration",
    "2640859": "For Xgboost there is the `scale_pos_weight` parameter or you can add `class_weights` when constructing the Dmatrix.\nIn case you use target encoding you could tune the `smoothing` parameter.",
    "2640942": "How it is a problem here?",
    "2641263": "I'm using StratifiedKFold (5 folds).",
    "2642150": "I think predicting positive(target 1 in home credit) will be difficult if it is.",
    "2642151": "Thank u for your knowledge!",
    "2642155": "The problem and difficulty of imbalanced data is explained here.\n\nhttps://machinelearningmastery.com/imbalanced-classification-is-hard/",
    "2644508": "thank you for your great experience!",
    "2670490": "I have recently posted a summary \"[Improving model performance by handling data imbalance](https://www.kaggle.com/competitions/home-credit-credit-risk-model-stability/discussion/478094)\" as to how imbalance can be handled in XGboost, LightGBM and CatBoost. At the end of the post there are also a few references from previous imbalanced Kaggle competitions. Hope it could be of a help, @takumimukaiyama.",
    "2671108": "For Xgboost you can also pass class weights during the Dmatrix creation. Could be worth testing.",
    "2671294": "Thanks, yes, I missed that. Will look through the source code to see if it is doing the same thing as weights passed to `XGBoost` constructor, and will update my post accordingly."
  },
  "source": "meta"
}