{
  "id": 33261,
  "title": "Keras Loss Function?",
  "url": "/competitions/intel-mobileodt-cervical-cancer-screening/discussion/33261",
  "author_name": "",
  "post_date": "2017-05-19T19:01:46.391873500Z",
  "votes": null,
  "comment_count": 7,
  "views": 0,
  "content": "<p>Hello Folks,</p>\n\n<p>I'm a student at General Assembly, and this is my first time I'm building a CNN. I was wondering - what loss function should we be using if we are using Keras?</p>\n\n<p>I noticed that there isn't a loss labeled log_loss in Keras's documentation, but it allows you to use Tensorflow losses. For that reason, I've been using tf.losses.log_loss (<a href=\"https://www.tensorflow.org/versions/master/api_docs/python/tf/losses/log_loss\">https://www.tensorflow.org/versions/master/api_docs/python/tf/losses/log_loss</a>)</p>\n\n<p>Looking at other people's kernels though, I see that others are using categorical_crossentropy and sparse_categorical_crossentropy. Should I be using one of those? Is there something wrong with me using tensorflow's log_loss?</p>\n\n<p>The reason I am asking is my validation loss is consistently double my Kaggle loss. I want to make sure that it's just an issue with my architecture or my preprocessing rather than something like using the wrong loss function.</p>\n\n<p>Appreciate the guidance!\n-Brendan</p>",
  "messages": [
    {
      "id": "183919",
      "postDate": "05/19/2017 19:01:46",
      "content": "<p>Hello Folks,</p>\n\n<p>I'm a student at General Assembly, and this is my first time I'm building a CNN. I was wondering - what loss function should we be using if we are using Keras?</p>\n\n<p>I noticed that there isn't a loss labeled log_loss in Keras's documentation, but it allows you to use Tensorflow losses. For that reason, I've been using tf.losses.log_loss (<a href=\"https://www.tensorflow.org/versions/master/api_docs/python/tf/losses/log_loss\">https://www.tensorflow.org/versions/master/api_docs/python/tf/losses/log_loss</a>)</p>\n\n<p>Looking at other people's kernels though, I see that others are using categorical_crossentropy and sparse_categorical_crossentropy. Should I be using one of those? Is there something wrong with me using tensorflow's log_loss?</p>\n\n<p>The reason I am asking is my validation loss is consistently double my Kaggle loss. I want to make sure that it's just an issue with my architecture or my preprocessing rather than something like using the wrong loss function.</p>\n\n<p>Appreciate the guidance!\n-Brendan</p>",
      "rawMarkdown": "Hello Folks,\n\nI'm a student at General Assembly, and this is my first time I'm building a CNN. I was wondering - what loss function should we be using if we are using Keras?\n\nI noticed that there isn't a loss labeled log_loss in Keras's documentation, but it allows you to use Tensorflow losses. For that reason, I've been using tf.losses.log_loss (https://www.tensorflow.org/versions/master/api_docs/python/tf/losses/log_loss)\n\nLooking at other people's kernels though, I see that others are using categorical_crossentropy and sparse_categorical_crossentropy. Should I be using one of those? Is there something wrong with me using tensorflow's log_loss?\n\nThe reason I am asking is my validation loss is consistently double my Kaggle loss. I want to make sure that it's just an issue with my architecture or my preprocessing rather than something like using the wrong loss function.\n\nAppreciate the guidance!\n-Brendan",
      "votes": null
    },
    {
      "id": "183923",
      "postDate": "05/19/2017 19:07:44",
      "content": "<p>Use categorical_crossentropy</p>",
      "rawMarkdown": "Use categorical_crossentropy",
      "votes": null
    },
    {
      "id": "183928",
      "postDate": "05/19/2017 19:20:59",
      "content": "<p>categorical_crossentropy is the same as log_loss\n<a href=\"http://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html\">http://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html</a>\nsparse_categorical_crossentropy uses integers (0,1,2,3,4...) instead of one-hot-encoded (001,010,100) vectors but is the same under the hood. If you have a large number of classes sparse_categorical_crossentropy allows to save some memory.</p>",
      "rawMarkdown": "categorical_crossentropy is the same as log_loss\nhttp://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html\nsparse_categorical_crossentropy uses integers (0,1,2,3,4...) instead of one-hot-encoded (001,010,100) vectors but is the same under the hood. If you have a large number of classes sparse_categorical_crossentropy allows to save some memory.",
      "votes": null
    },
    {
      "id": "183929",
      "postDate": "05/19/2017 19:26:34",
      "content": "<p>Thanks Dennis - that's really helpful!</p>",
      "rawMarkdown": "Thanks Dennis - that's really helpful!",
      "votes": null
    },
    {
      "id": "183932",
      "postDate": "05/19/2017 19:50:40",
      "content": "<p>With so much missing data ?</p>",
      "rawMarkdown": "With so much missing data ?",
      "votes": null
    },
    {
      "id": "183934",
      "postDate": "05/19/2017 19:53:11",
      "content": "<p>What missing data?</p>",
      "rawMarkdown": "What missing data?",
      "votes": null
    },
    {
      "id": "184218",
      "postDate": "05/21/2017 00:54:52",
      "content": "<p>categorical_crossentropy sounds like a good choice, I am not sure of using the log_loss which the competition provided is a good idea, I am still going through the relationship with the log_loss and categorical_crossentropy, I mean there should be some relationship between, but maybe I won't use log_loss directly for training :)</p>",
      "rawMarkdown": "categorical_crossentropy sounds like a good choice, I am not sure of using the log_loss which the competition provided is a good idea, I am still going through the relationship with the log_loss and categorical_crossentropy, I mean there should be some relationship between, but maybe I won't use log_loss directly for training :)",
      "votes": null
    },
    {
      "id": "184388",
      "postDate": "05/21/2017 17:11:52",
      "content": "<p>They are the same.</p>",
      "rawMarkdown": "They are the same.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 183923,
      "author_name": "CVxTz",
      "author_url": "",
      "post_date": "05/19/2017 19:07:44",
      "content": "<p>Use categorical_crossentropy</p>",
      "votes": null,
      "replies": [
        {
          "id": 183932,
          "author_name": "pfichou",
          "author_url": "",
          "post_date": "05/19/2017 19:50:40",
          "content": "<p>With so much missing data ?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 183934,
          "author_name": "sakvaua",
          "author_url": "",
          "post_date": "05/19/2017 19:53:11",
          "content": "<p>What missing data?</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 183928,
      "author_name": "sakvaua",
      "author_url": "",
      "post_date": "05/19/2017 19:20:59",
      "content": "<p>categorical_crossentropy is the same as log_loss\n<a href=\"http://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html\">http://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html</a>\nsparse_categorical_crossentropy uses integers (0,1,2,3,4...) instead of one-hot-encoded (001,010,100) vectors but is the same under the hood. If you have a large number of classes sparse_categorical_crossentropy allows to save some memory.</p>",
      "votes": null,
      "replies": [
        {
          "id": 183929,
          "author_name": "bbailey",
          "author_url": "",
          "post_date": "05/19/2017 19:26:34",
          "content": "<p>Thanks Dennis - that's really helpful!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 184218,
      "author_name": "rinesnow",
      "author_url": "",
      "post_date": "05/21/2017 00:54:52",
      "content": "<p>categorical_crossentropy sounds like a good choice, I am not sure of using the log_loss which the competition provided is a good idea, I am still going through the relationship with the log_loss and categorical_crossentropy, I mean there should be some relationship between, but maybe I won't use log_loss directly for training :)</p>",
      "votes": null,
      "replies": [
        {
          "id": 184388,
          "author_name": "sakvaua",
          "author_url": "",
          "post_date": "05/21/2017 17:11:52",
          "content": "<p>They are the same.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "183919": "Hello Folks,\n\nI'm a student at General Assembly, and this is my first time I'm building a CNN. I was wondering - what loss function should we be using if we are using Keras?\n\nI noticed that there isn't a loss labeled log_loss in Keras's documentation, but it allows you to use Tensorflow losses. For that reason, I've been using tf.losses.log_loss (https://www.tensorflow.org/versions/master/api_docs/python/tf/losses/log_loss)\n\nLooking at other people's kernels though, I see that others are using categorical_crossentropy and sparse_categorical_crossentropy. Should I be using one of those? Is there something wrong with me using tensorflow's log_loss?\n\nThe reason I am asking is my validation loss is consistently double my Kaggle loss. I want to make sure that it's just an issue with my architecture or my preprocessing rather than something like using the wrong loss function.\n\nAppreciate the guidance!\n-Brendan",
    "183923": "Use categorical_crossentropy",
    "183928": "categorical_crossentropy is the same as log_loss\nhttp://scikit-learn.org/stable/modules/generated/sklearn.metrics.log_loss.html\nsparse_categorical_crossentropy uses integers (0,1,2,3,4...) instead of one-hot-encoded (001,010,100) vectors but is the same under the hood. If you have a large number of classes sparse_categorical_crossentropy allows to save some memory.",
    "183929": "Thanks Dennis - that's really helpful!",
    "183932": "With so much missing data ?",
    "183934": "What missing data?",
    "184218": "categorical_crossentropy sounds like a good choice, I am not sure of using the log_loss which the competition provided is a good idea, I am still going through the relationship with the log_loss and categorical_crossentropy, I mean there should be some relationship between, but maybe I won't use log_loss directly for training :)",
    "184388": "They are the same."
  },
  "source": "meta"
}