{
  "id": 45463,
  "title": "Scaling Categorical Features with the rest of the dataset.",
  "url": "/competitions/favorita-grocery-sales-forecasting/discussion/45463",
  "author_name": "",
  "post_date": "2017-12-11T16:41:45.521063300Z",
  "votes": null,
  "comment_count": 5,
  "views": 0,
  "content": "<p>I'm new in Kaggle, and it's my First compettitoin.</p>\n\n<p>I have a question regarding the feature scaling process.</p>\n\n<p>Can I scale Features as id, store_nbr, item_nbr and others that has a categorical representation of a certain item, store and etc. Or I should left them out of the feature scaling step and add them later as the algorithm would understand them as categorical variables?</p>\n\n<p>Now, i'm scaling the whole dataset, except the unit_sales variable. </p>\n\n<p>Can someone explain to me what is the best practice towards feature scaling?</p>\n\n<p>Many Thanks.</p>",
  "messages": [
    {
      "id": "256277",
      "postDate": "12/11/2017 16:41:45",
      "content": "<p>I'm new in Kaggle, and it's my First compettitoin.</p>\n\n<p>I have a question regarding the feature scaling process.</p>\n\n<p>Can I scale Features as id, store_nbr, item_nbr and others that has a categorical representation of a certain item, store and etc. Or I should left them out of the feature scaling step and add them later as the algorithm would understand them as categorical variables?</p>\n\n<p>Now, i'm scaling the whole dataset, except the unit_sales variable. </p>\n\n<p>Can someone explain to me what is the best practice towards feature scaling?</p>\n\n<p>Many Thanks.</p>",
      "rawMarkdown": "I'm new in Kaggle, and it's my First compettitoin.\n\nI have a question regarding the feature scaling process.\n\nCan I scale Features as id, store_nbr, item_nbr and others that has a categorical representation of a certain item, store and etc. Or I should left them out of the feature scaling step and add them later as the algorithm would understand them as categorical variables?\n\nNow, i'm scaling the whole dataset, except the unit_sales variable. \n\nCan someone explain to me what is the best practice towards feature scaling?\n\nMany Thanks.",
      "votes": null
    },
    {
      "id": "256325",
      "postDate": "12/11/2017 18:19:05",
      "content": "<p>Its good that you had the intuition to know there's something weird going on with scaling the categorical features. You're right, you shouldn't do that. </p>\n\n<p>A decent way to encode, say, 54 store numbers would be to use a one hot encoding. The store number 3 is repesented by [0, 0, 1, ...], while store 5 is [0, 0, 0, 0, 1, ...], where the length of the list is 54 in all cases. </p>",
      "rawMarkdown": "Its good that you had the intuition to know there's something weird going on with scaling the categorical features. You're right, you shouldn't do that. \n\nA decent way to encode, say, 54 store numbers would be to use a one hot encoding. The store number 3 is repesented by [0, 0, 1, ...], while store 5 is [0, 0, 0, 0, 1, ...], where the length of the list is 54 in all cases.",
      "votes": null
    },
    {
      "id": "256327",
      "postDate": "12/11/2017 18:22:55",
      "content": "<p>If you intend to use tree-based models, there's no need to scale the categorical data. If it's not a number, you can convert it by just applying LabelEncoding (just assign a unique number to a unique category) and you're good to go.</p>",
      "rawMarkdown": "If you intend to use tree-based models, there's no need to scale the categorical data. If it's not a number, you can convert it by just applying LabelEncoding (just assign a unique number to a unique category) and you're good to go.",
      "votes": null
    },
    {
      "id": "256340",
      "postDate": "12/11/2017 19:02:40",
      "content": "<p>Alright, It's going to increase considerably the size of the dataset but it seem a reasonable approach. Thanks.</p>",
      "rawMarkdown": "Alright, It's going to increase considerably the size of the dataset but it seem a reasonable approach. Thanks.",
      "votes": null
    },
    {
      "id": "256341",
      "postDate": "12/11/2017 19:03:24",
      "content": "<p>I am using some tree-based models in an ensemble, I will try this option as well, Thanks.</p>",
      "rawMarkdown": "I am using some tree-based models in an ensemble, I will try this option as well, Thanks.",
      "votes": null
    },
    {
      "id": "258034",
      "postDate": "12/15/2017 09:44:40",
      "content": "<p>Hi,</p>\n\n<p>Scaling is used for non-tree based models, because if two measures are scaled differently and the euclidean distance might have huge impact on the values. If we scale the measures either by min-max and standard scaling then we will have  meaning full euclidean distance.</p>\n\n<p>In tree based models, we don't scale the measures. In tree bases algorithm it will make different boundaries based on the values. My suggestion is try to bin the measures according to the data pattern and then apply tree based algorithm.</p>\n\n<p>I hope it helped you.</p>",
      "rawMarkdown": "Hi,\n \n Scaling is used for non-tree based models, because if two measures are scaled differently and the euclidean distance might have huge impact on the values. If we scale the measures either by min-max and standard scaling then we will have  meaning full euclidean distance.\n\nIn tree based models, we don't scale the measures. In tree bases algorithm it will make different boundaries based on the values. My suggestion is try to bin the measures according to the data pattern and then apply tree based algorithm.\n\nI hope it helped you.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 256325,
      "author_name": "vannak",
      "author_url": "",
      "post_date": "12/11/2017 18:19:05",
      "content": "<p>Its good that you had the intuition to know there's something weird going on with scaling the categorical features. You're right, you shouldn't do that. </p>\n\n<p>A decent way to encode, say, 54 store numbers would be to use a one hot encoding. The store number 3 is repesented by [0, 0, 1, ...], while store 5 is [0, 0, 0, 0, 1, ...], where the length of the list is 54 in all cases. </p>",
      "votes": null,
      "replies": [
        {
          "id": 256340,
          "author_name": "mboaretto",
          "author_url": "",
          "post_date": "12/11/2017 19:02:40",
          "content": "<p>Alright, It's going to increase considerably the size of the dataset but it seem a reasonable approach. Thanks.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 256327,
      "author_name": "lgmoneda",
      "author_url": "",
      "post_date": "12/11/2017 18:22:55",
      "content": "<p>If you intend to use tree-based models, there's no need to scale the categorical data. If it's not a number, you can convert it by just applying LabelEncoding (just assign a unique number to a unique category) and you're good to go.</p>",
      "votes": null,
      "replies": [
        {
          "id": 256341,
          "author_name": "mboaretto",
          "author_url": "",
          "post_date": "12/11/2017 19:03:24",
          "content": "<p>I am using some tree-based models in an ensemble, I will try this option as well, Thanks.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 258034,
      "author_name": "yatishbn",
      "author_url": "",
      "post_date": "12/15/2017 09:44:40",
      "content": "<p>Hi,</p>\n\n<p>Scaling is used for non-tree based models, because if two measures are scaled differently and the euclidean distance might have huge impact on the values. If we scale the measures either by min-max and standard scaling then we will have  meaning full euclidean distance.</p>\n\n<p>In tree based models, we don't scale the measures. In tree bases algorithm it will make different boundaries based on the values. My suggestion is try to bin the measures according to the data pattern and then apply tree based algorithm.</p>\n\n<p>I hope it helped you.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "256277": "I'm new in Kaggle, and it's my First compettitoin.\n\nI have a question regarding the feature scaling process.\n\nCan I scale Features as id, store_nbr, item_nbr and others that has a categorical representation of a certain item, store and etc. Or I should left them out of the feature scaling step and add them later as the algorithm would understand them as categorical variables?\n\nNow, i'm scaling the whole dataset, except the unit_sales variable. \n\nCan someone explain to me what is the best practice towards feature scaling?\n\nMany Thanks.",
    "256325": "Its good that you had the intuition to know there's something weird going on with scaling the categorical features. You're right, you shouldn't do that. \n\nA decent way to encode, say, 54 store numbers would be to use a one hot encoding. The store number 3 is repesented by [0, 0, 1, ...], while store 5 is [0, 0, 0, 0, 1, ...], where the length of the list is 54 in all cases.",
    "256327": "If you intend to use tree-based models, there's no need to scale the categorical data. If it's not a number, you can convert it by just applying LabelEncoding (just assign a unique number to a unique category) and you're good to go.",
    "256340": "Alright, It's going to increase considerably the size of the dataset but it seem a reasonable approach. Thanks.",
    "256341": "I am using some tree-based models in an ensemble, I will try this option as well, Thanks.",
    "258034": "Hi,\n \n Scaling is used for non-tree based models, because if two measures are scaled differently and the euclidean distance might have huge impact on the values. If we scale the measures either by min-max and standard scaling then we will have  meaning full euclidean distance.\n\nIn tree based models, we don't scale the measures. In tree bases algorithm it will make different boundaries based on the values. My suggestion is try to bin the measures according to the data pattern and then apply tree based algorithm.\n\nI hope it helped you."
  },
  "source": "meta"
}