{
  "id": 108158,
  "title": "Modified classification loss function to achieve good performance similar to MSE loss in regression",
  "url": "/competitions/aptos2019-blindness-detection/discussion/108158",
  "author_name": "",
  "post_date": "2019-09-09T14:12:19.712782400Z",
  "votes": 12,
  "comment_count": 1,
  "views": 0,
  "content": "<p>Congrats to all the winners!</p>\n\n<p>This is my first competition I spent much time finishing, looking back on it, there is still much work can be done, scores can also be improved.</p>\n\n<p>In the early part of the competition, it was generally discussed whether we should treat the competition as <strong>a classification problem or a regression problem</strong>.</p>\n\n<p>Upon publication of PL results, most of the top teams used regression. So I just want to share a classification loss I used in this competition, which can achieve good performance similar to MSE loss in regression according my experiments.</p>\n\n<p>Submissions are scored based on the <strong>quadratic weighted kappa</strong>, which measures the agreement between two ratings. Simply, the penalty for predicting class = 0 to 4 should be 16 times that the predicting class = 0 to class = 1. so MSE loss can get a good score and I added a <strong>penalty</strong> to modify the BCEWithLogitsLoss function to BCEWithPenalty function. <strong>The larger the gap between prediction and truth, the larger the penalty.</strong>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F0ff55a7845e591233975232c6a6566f1%2FEXAMPLE.png?generation=1568168069390502&amp;alt=media\" alt=\"\"></p>\n\n<p><strong>Pytorch code as follows.</strong></p>\n\n<p><strong>Loss function</strong>:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F4b895b093618c2fb8563950ee2f422c9%2Floss.png?generation=1568038132989648&amp;alt=media\" alt=\"\"></p>\n\n<p><strong>Dataset example</strong>:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2Fc1c8cb8aa849daede2bbf914168b06fe%2Fdataste.png?generation=1568038146657575&amp;alt=media\" alt=\"\"></p>\n\n<p><strong>Model example</strong>: \n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F1b2c032b2363d4abee13a1443cc5b0e2%2Fmodel.png?generation=1568038157504859&amp;alt=media\" alt=\"\"></p>\n\n<p>In this way,  you can ensemble more <strong>diverse</strong> models.\n<strong>Hope you guys can get the same performance with the methods you used in regression models.</strong></p>",
  "messages": [
    {
      "id": "622336",
      "postDate": "09/09/2019 14:12:19",
      "content": "<p>Congrats to all the winners!</p>\n\n<p>This is my first competition I spent much time finishing, looking back on it, there is still much work can be done, scores can also be improved.</p>\n\n<p>In the early part of the competition, it was generally discussed whether we should treat the competition as <strong>a classification problem or a regression problem</strong>.</p>\n\n<p>Upon publication of PL results, most of the top teams used regression. So I just want to share a classification loss I used in this competition, which can achieve good performance similar to MSE loss in regression according my experiments.</p>\n\n<p>Submissions are scored based on the <strong>quadratic weighted kappa</strong>, which measures the agreement between two ratings. Simply, the penalty for predicting class = 0 to 4 should be 16 times that the predicting class = 0 to class = 1. so MSE loss can get a good score and I added a <strong>penalty</strong> to modify the BCEWithLogitsLoss function to BCEWithPenalty function. <strong>The larger the gap between prediction and truth, the larger the penalty.</strong>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F0ff55a7845e591233975232c6a6566f1%2FEXAMPLE.png?generation=1568168069390502&amp;alt=media\" alt=\"\"></p>\n\n<p><strong>Pytorch code as follows.</strong></p>\n\n<p><strong>Loss function</strong>:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F4b895b093618c2fb8563950ee2f422c9%2Floss.png?generation=1568038132989648&amp;alt=media\" alt=\"\"></p>\n\n<p><strong>Dataset example</strong>:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2Fc1c8cb8aa849daede2bbf914168b06fe%2Fdataste.png?generation=1568038146657575&amp;alt=media\" alt=\"\"></p>\n\n<p><strong>Model example</strong>: \n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F1b2c032b2363d4abee13a1443cc5b0e2%2Fmodel.png?generation=1568038157504859&amp;alt=media\" alt=\"\"></p>\n\n<p>In this way,  you can ensemble more <strong>diverse</strong> models.\n<strong>Hope you guys can get the same performance with the methods you used in regression models.</strong></p>",
      "rawMarkdown": "Congrats to all the winners!\n\nThis is my first competition I spent much time finishing, looking back on it, there is still much work can be done, scores can also be improved.\n\nIn the early part of the competition, it was generally discussed whether we should treat the competition as **a classification problem or a regression problem**.\n\nUpon publication of PL results, most of the top teams used regression. So I just want to share a classification loss I used in this competition, which can achieve good performance similar to MSE loss in regression according my experiments.\n\nSubmissions are scored based on the **quadratic weighted kappa**, which measures the agreement between two ratings. Simply, the penalty for predicting class = 0 to 4 should be 16 times that the predicting class = 0 to class = 1. so MSE loss can get a good score and I added a **penalty** to modify the BCEWithLogitsLoss function to BCEWithPenalty function. **The larger the gap between prediction and truth, the larger the penalty.**\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F0ff55a7845e591233975232c6a6566f1%2FEXAMPLE.png?generation=1568168069390502&amp;alt=media)\n\n\n**Pytorch code as follows.**\n\n**Loss function**:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F4b895b093618c2fb8563950ee2f422c9%2Floss.png?generation=1568038132989648&amp;alt=media)\n\n\n**Dataset example**:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2Fc1c8cb8aa849daede2bbf914168b06fe%2Fdataste.png?generation=1568038146657575&amp;alt=media)\n\n\n**Model example**: \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F1b2c032b2363d4abee13a1443cc5b0e2%2Fmodel.png?generation=1568038157504859&amp;alt=media)\n\n\n\n\nIn this way,  you can ensemble more **diverse** models.\n**Hope you guys can get the same performance with the methods you used in regression models.**",
      "votes": null
    },
    {
      "id": "622669",
      "postDate": "09/10/2019 00:28:48",
      "content": "<p>simple but nice work 😊 </p>",
      "rawMarkdown": "simple but nice work 😊",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 622669,
      "author_name": "zengshisan",
      "author_url": "",
      "post_date": "09/10/2019 00:28:48",
      "content": "<p>simple but nice work 😊 </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "622336": "Congrats to all the winners!\n\nThis is my first competition I spent much time finishing, looking back on it, there is still much work can be done, scores can also be improved.\n\nIn the early part of the competition, it was generally discussed whether we should treat the competition as **a classification problem or a regression problem**.\n\nUpon publication of PL results, most of the top teams used regression. So I just want to share a classification loss I used in this competition, which can achieve good performance similar to MSE loss in regression according my experiments.\n\nSubmissions are scored based on the **quadratic weighted kappa**, which measures the agreement between two ratings. Simply, the penalty for predicting class = 0 to 4 should be 16 times that the predicting class = 0 to class = 1. so MSE loss can get a good score and I added a **penalty** to modify the BCEWithLogitsLoss function to BCEWithPenalty function. **The larger the gap between prediction and truth, the larger the penalty.**\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F0ff55a7845e591233975232c6a6566f1%2FEXAMPLE.png?generation=1568168069390502&amp;alt=media)\n\n\n**Pytorch code as follows.**\n\n**Loss function**:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F4b895b093618c2fb8563950ee2f422c9%2Floss.png?generation=1568038132989648&amp;alt=media)\n\n\n**Dataset example**:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2Fc1c8cb8aa849daede2bbf914168b06fe%2Fdataste.png?generation=1568038146657575&amp;alt=media)\n\n\n**Model example**: \n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F2875360%2F1b2c032b2363d4abee13a1443cc5b0e2%2Fmodel.png?generation=1568038157504859&amp;alt=media)\n\n\n\n\nIn this way,  you can ensemble more **diverse** models.\n**Hope you guys can get the same performance with the methods you used in regression models.**",
    "622669": "simple but nice work 😊"
  },
  "source": "meta"
}