{
  "id": 164295,
  "title": "Using Class Weights During training",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/164295",
  "author_name": "",
  "post_date": "2020-07-05T15:04:45.162367100Z",
  "votes": 7,
  "comment_count": 3,
  "views": 0,
  "content": "<p>I was experimenting with single model predictions. There is concept of <strong><em>class weights</em></strong> [see <a href=\"https://www.tensorflow.org/tutorials/structured_data/imbalanced_data#class_weights\">this</a> for more info] and got very unexpected results.\n<strong>Model:</strong> efficientnetb6\n<strong>Dataset:</strong> 384x384 melanoma images [<a href=\"https://www.kaggle.com/cdeotte/melanoma-384x384\">link</a>]</p>\n\n<p><strong>RESULTS</strong>\n* class weights as {0: 0.5089, 1: 28.3613} [using formula] --&gt; 0.887 [<a href=\"https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38125072\">NOTEBOOK</a>]\n* class weights as {0: 0.1, 1: 1} --&gt; 0.885 [<a href=\"https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38125072\">NOTEBOOK</a>] \n* without class weights --&gt; 0.82 [<a href=\"https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38127955\">NOTEBOOK</a>]</p>\n\n<p><strong>NOTE:</strong> No CV, very little Augmentation, no post processing and ensemble</p>",
  "messages": [
    {
      "id": "916334",
      "postDate": "07/05/2020 15:04:45",
      "content": "<p>I was experimenting with single model predictions. There is concept of <strong><em>class weights</em></strong> [see <a href=\"https://www.tensorflow.org/tutorials/structured_data/imbalanced_data#class_weights\">this</a> for more info] and got very unexpected results.\n<strong>Model:</strong> efficientnetb6\n<strong>Dataset:</strong> 384x384 melanoma images [<a href=\"https://www.kaggle.com/cdeotte/melanoma-384x384\">link</a>]</p>\n\n<p><strong>RESULTS</strong>\n* class weights as {0: 0.5089, 1: 28.3613} [using formula] --&gt; 0.887 [<a href=\"https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38125072\">NOTEBOOK</a>]\n* class weights as {0: 0.1, 1: 1} --&gt; 0.885 [<a href=\"https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38125072\">NOTEBOOK</a>] \n* without class weights --&gt; 0.82 [<a href=\"https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38127955\">NOTEBOOK</a>]</p>\n\n<p><strong>NOTE:</strong> No CV, very little Augmentation, no post processing and ensemble</p>",
      "rawMarkdown": "I was experimenting with single model predictions. There is concept of **_class weights_** [see [this](https://www.tensorflow.org/tutorials/structured_data/imbalanced_data#class_weights) for more info] and got very unexpected results.\n**Model:** efficientnetb6\n**Dataset:** 384x384 melanoma images [[link](https://www.kaggle.com/cdeotte/melanoma-384x384)]\n\n**RESULTS**\n* class weights as {0: 0.5089, 1: 28.3613} [using formula] --&gt; 0.887 [[NOTEBOOK](https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38125072)]\n* class weights as {0: 0.1, 1: 1} --&gt; 0.885 [[NOTEBOOK](https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38125072)] \n* without class weights --&gt; 0.82 [[NOTEBOOK](https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38127955)]\n\n**NOTE:** No CV, very little Augmentation, no post processing and ensemble",
      "votes": null
    },
    {
      "id": "916531",
      "postDate": "07/05/2020 18:24:15",
      "content": "<p>Due to the imbalance of data I think the class weights are necessary. Depending on the application it may be more desirable to have FP or FN. For example, my research for my Masters is focused on finding abnormal frames in a video of a wireless capsule endoscopy. To the physician its more important to not miss any abnormality than it is to have a few normal frames misclassified. So by varying the weights I can force more of that kind of error so the performance is reduced as far as accuracy is concerned, but for the application it is what's needed.</p>",
      "rawMarkdown": "Due to the imbalance of data I think the class weights are necessary. Depending on the application it may be more desirable to have FP or FN. For example, my research for my Masters is focused on finding abnormal frames in a video of a wireless capsule endoscopy. To the physician its more important to not miss any abnormality than it is to have a few normal frames misclassified. So by varying the weights I can force more of that kind of error so the performance is reduced as far as accuracy is concerned, but for the application it is what's needed.",
      "votes": null
    },
    {
      "id": "916615",
      "postDate": "07/05/2020 20:59:36",
      "content": "<p>Interesting, I have done some experiments with class weights but did not got relevant improvents, I have even tried some different weights configurations.</p>",
      "rawMarkdown": "Interesting, I have done some experiments with class weights but did not got relevant improvents, I have even tried some different weights configurations.",
      "votes": null
    },
    {
      "id": "916900",
      "postDate": "07/06/2020 05:25:56",
      "content": "<p><a href=\"/dimitreoliveira\">@dimitreoliveira</a> If you are using class weights try to train it for more number of epochs (around 20 or 30).</p>",
      "rawMarkdown": "dimitreoliveira If you are using class weights try to train it for more number of epochs (around 20 or 30).",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 916531,
      "author_name": "hmorera",
      "author_url": "",
      "post_date": "07/05/2020 18:24:15",
      "content": "<p>Due to the imbalance of data I think the class weights are necessary. Depending on the application it may be more desirable to have FP or FN. For example, my research for my Masters is focused on finding abnormal frames in a video of a wireless capsule endoscopy. To the physician its more important to not miss any abnormality than it is to have a few normal frames misclassified. So by varying the weights I can force more of that kind of error so the performance is reduced as far as accuracy is concerned, but for the application it is what's needed.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 916615,
      "author_name": "dimitreoliveira",
      "author_url": "",
      "post_date": "07/05/2020 20:59:36",
      "content": "<p>Interesting, I have done some experiments with class weights but did not got relevant improvents, I have even tried some different weights configurations.</p>",
      "votes": null,
      "replies": [
        {
          "id": 916900,
          "author_name": "orionpax00",
          "author_url": "",
          "post_date": "07/06/2020 05:25:56",
          "content": "<p><a href=\"/dimitreoliveira\">@dimitreoliveira</a> If you are using class weights try to train it for more number of epochs (around 20 or 30).</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "916334": "I was experimenting with single model predictions. There is concept of **_class weights_** [see [this](https://www.tensorflow.org/tutorials/structured_data/imbalanced_data#class_weights) for more info] and got very unexpected results.\n**Model:** efficientnetb6\n**Dataset:** 384x384 melanoma images [[link](https://www.kaggle.com/cdeotte/melanoma-384x384)]\n\n**RESULTS**\n* class weights as {0: 0.5089, 1: 28.3613} [using formula] --&gt; 0.887 [[NOTEBOOK](https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38125072)]\n* class weights as {0: 0.1, 1: 1} --&gt; 0.885 [[NOTEBOOK](https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38125072)] \n* without class weights --&gt; 0.82 [[NOTEBOOK](https://www.kaggle.com/orionpax00/melanoma-detection-single-model-gpu-tpu-yapl?scriptVersionId=38127955)]\n\n**NOTE:** No CV, very little Augmentation, no post processing and ensemble",
    "916531": "Due to the imbalance of data I think the class weights are necessary. Depending on the application it may be more desirable to have FP or FN. For example, my research for my Masters is focused on finding abnormal frames in a video of a wireless capsule endoscopy. To the physician its more important to not miss any abnormality than it is to have a few normal frames misclassified. So by varying the weights I can force more of that kind of error so the performance is reduced as far as accuracy is concerned, but for the application it is what's needed.",
    "916615": "Interesting, I have done some experiments with class weights but did not got relevant improvents, I have even tried some different weights configurations.",
    "916900": "dimitreoliveira If you are using class weights try to train it for more number of epochs (around 20 or 30)."
  },
  "source": "meta"
}