{
  "id": 103689,
  "title": "multilabel classification and loss function",
  "url": "/competitions/aptos2019-blindness-detection/discussion/103689",
  "author_name": "",
  "post_date": "2019-08-11T03:31:06.529849100Z",
  "votes": 1,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hi guys, \n I'm a total novice to this and would like to ask a few basic questions to get started.\n1. Since this can be viewed as a multilabel classification task, if the last layer is Dense(5, activation = 'softmax'), do you have to transform the y(label) to something like [0,0,1,0,0] or there are other better ways to do this?\n2. If the y format is indeed transformed to [0,0,1,0,0], then what would be the best choice of loss function and accuracy function, why? </p>\n\n<p>Many thanks for the help!</p>",
  "messages": [
    {
      "id": "596648",
      "postDate": "08/11/2019 03:31:06",
      "content": "<p>Hi guys, \n I'm a total novice to this and would like to ask a few basic questions to get started.\n1. Since this can be viewed as a multilabel classification task, if the last layer is Dense(5, activation = 'softmax'), do you have to transform the y(label) to something like [0,0,1,0,0] or there are other better ways to do this?\n2. If the y format is indeed transformed to [0,0,1,0,0], then what would be the best choice of loss function and accuracy function, why? </p>\n\n<p>Many thanks for the help!</p>",
      "rawMarkdown": "Hi guys, \n I'm a total novice to this and would like to ask a few basic questions to get started.\n1. Since this can be viewed as a multilabel classification task, if the last layer is Dense(5, activation = 'softmax'), do you have to transform the y(label) to something like [0,0,1,0,0] or there are other better ways to do this?\n2. If the y format is indeed transformed to [0,0,1,0,0], then what would be the best choice of loss function and accuracy function, why? \n\nMany thanks for the help!",
      "votes": null
    },
    {
      "id": "597412",
      "postDate": "08/12/2019 09:56:53",
      "content": "<p>in keras:\nthe form of y depends on loss function you choose. if you choose:\ncategorical_crossentropy: y should be one-hot coded vector like [0,0,1,0,0] which represents probablities for each class.\nsparse_categorical_crossentropy: y should be a integer, for example, integer 2 means class-2, etc.</p>\n\n<p>see the source code or api reference for those functions to get more information.</p>\n\n<p>typically, we use crossentropy as loss function for multilabel classification.</p>",
      "rawMarkdown": "in keras:\nthe form of y depends on loss function you choose. if you choose:\ncategorical_crossentropy: y should be one-hot coded vector like [0,0,1,0,0] which represents probablities for each class.\nsparse_categorical_crossentropy: y should be a integer, for example, integer 2 means class-2, etc.\n\nsee the source code or api reference for those functions to get more information.\n\ntypically, we use crossentropy as loss function for multilabel classification.",
      "votes": null
    },
    {
      "id": "598171",
      "postDate": "08/13/2019 08:26:10",
      "content": "<p>Multilabel and softmax doesn't seem like a good choice.\nMultilabel means the target can correspond to several labels - like [2, 4], or [0, 0, 1, 0, 1]\nIf you do encode target this way, you can use zero-one encoding(like [0, 0, 1, 0, 1]), sigmoid activation and binary cross-entropy as loss.</p>\n\n<p>If you really mean multiclass classifciation - you can use softmax activation, and sparse categorical cross-entropy as loss function or perform one-hot encoding and use categorical cross-entropy. </p>",
      "rawMarkdown": "Multilabel and softmax doesn't seem like a good choice.\nMultilabel means the target can correspond to several labels - like [2, 4], or [0, 0, 1, 0, 1]\nIf you do encode target this way, you can use zero-one encoding(like [0, 0, 1, 0, 1]), sigmoid activation and binary cross-entropy as loss.\n\nIf you really mean multiclass classifciation - you can use softmax activation, and sparse categorical cross-entropy as loss function or perform one-hot encoding and use categorical cross-entropy.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 597412,
      "author_name": "frank518",
      "author_url": "",
      "post_date": "08/12/2019 09:56:53",
      "content": "<p>in keras:\nthe form of y depends on loss function you choose. if you choose:\ncategorical_crossentropy: y should be one-hot coded vector like [0,0,1,0,0] which represents probablities for each class.\nsparse_categorical_crossentropy: y should be a integer, for example, integer 2 means class-2, etc.</p>\n\n<p>see the source code or api reference for those functions to get more information.</p>\n\n<p>typically, we use crossentropy as loss function for multilabel classification.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 598171,
      "author_name": "vzaguskin",
      "author_url": "",
      "post_date": "08/13/2019 08:26:10",
      "content": "<p>Multilabel and softmax doesn't seem like a good choice.\nMultilabel means the target can correspond to several labels - like [2, 4], or [0, 0, 1, 0, 1]\nIf you do encode target this way, you can use zero-one encoding(like [0, 0, 1, 0, 1]), sigmoid activation and binary cross-entropy as loss.</p>\n\n<p>If you really mean multiclass classifciation - you can use softmax activation, and sparse categorical cross-entropy as loss function or perform one-hot encoding and use categorical cross-entropy. </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "596648": "Hi guys, \n I'm a total novice to this and would like to ask a few basic questions to get started.\n1. Since this can be viewed as a multilabel classification task, if the last layer is Dense(5, activation = 'softmax'), do you have to transform the y(label) to something like [0,0,1,0,0] or there are other better ways to do this?\n2. If the y format is indeed transformed to [0,0,1,0,0], then what would be the best choice of loss function and accuracy function, why? \n\nMany thanks for the help!",
    "597412": "in keras:\nthe form of y depends on loss function you choose. if you choose:\ncategorical_crossentropy: y should be one-hot coded vector like [0,0,1,0,0] which represents probablities for each class.\nsparse_categorical_crossentropy: y should be a integer, for example, integer 2 means class-2, etc.\n\nsee the source code or api reference for those functions to get more information.\n\ntypically, we use crossentropy as loss function for multilabel classification.",
    "598171": "Multilabel and softmax doesn't seem like a good choice.\nMultilabel means the target can correspond to several labels - like [2, 4], or [0, 0, 1, 0, 1]\nIf you do encode target this way, you can use zero-one encoding(like [0, 0, 1, 0, 1]), sigmoid activation and binary cross-entropy as loss.\n\nIf you really mean multiclass classifciation - you can use softmax activation, and sparse categorical cross-entropy as loss function or perform one-hot encoding and use categorical cross-entropy."
  },
  "source": "meta"
}