Answers.Body: <p>Authors use many different approaches.</p>
  
  <p>One approach is to have a different input neuron for each possible category, and then use a "1-hot" encoding. So if you have 10 categories, then you can encode this as 10 binary features.</p>
  
  <p>Another is to use some sort of binary encoding. If you have 10 categories, it is sufficient to use 4 neurons to represent all possible categories by using binary numbers.</p>
  
  <p>A third approach is to convert your categories to cardinal values, and then normalize them. This may be more effective if your categories really are cardinal (i.e. orderable). If there isn't a natural ordering to them though, this might lead to strange results or make the problem difficult to learn (since it ends up embedding non-linear relationships in the learning problem that don't need to exist).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-01T12:34:15.543Z
Answers.Text: @DuttaA I agree. It has many of the same problems as a cardinal encoding (i.e. introducing non-linear patterns to learn). I have seen it used from time to time however.
Answers.UserDisplayName: John Doucette
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-01T12:14:09.567Z
Answers.LastActivityDate: 2018-09-01T12:14:09.567Z
Answers.UserDisplayName: John Doucette
Answers.Body: <p>A one-hot encoding, as described in <a href="https://ai.stackexchange.com/questions/7781/how-to-model-categorical-variables-enums/7783#7783">John's answer</a>, is probably the most straightforward / simple solution (maybe even the most common?). It is not without its problems though. For example, if you have a large number of such categorical variables, and each has a large number of possible values, the number of binary inputs you need for one-hot encodings may grow too large.</p>
  
  <blockquote>
    <p>Lets say we have a data set and 2 of its features are home_team and away_team, the possible values of these 2 features are all the NBA teams.</p>
  </blockquote>
  
  <p>In this specific example, a different possible solution might be not to use the "identity" of a team as a feature itself, but try to find a number of (ideally numeric) features corresponding to that team.</p>
  
  <p>For example, instead of trying to encode "home_team" in some way in your inputs, you could (if you manage to find the data you need to do this) use the following features (not really familiar with NBA, so not sure if all these make sense):</p>
  
  <ul>
  <li>Win percentage of home_team in recent X amount of time</li>
  <li>Historical win percentage of home_team against away_team</li>
  <li>Average points scored per match by this team</li>
  <li>In football there's something like how many minutes per game a team is "in control" of the ball, is there something similar in NBA maybe?</li>
  <li>etc.</li>
  </ul>
  
  <p>And then you can try to get a similar list of features for the away_team. </p>
  
  <p>This kind of solution would work for your example, and maybe also for various other examples. It might not work in all cases of categorical features though, in some cases you'd have to revert to solutions like those in John's answer.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-01T14:16:20.243Z
Answers.LastActivityDate: 2018-09-01T14:16:20.243Z
Answers.UserDisplayName: Dennis Soemers
Body: <p>I am new to the field and I am trying to understand how is possible to use categorical variables / enums?</p>
  
  <p>Lets say we have a data set and 2 of its features are <code>home_team</code> and <code>away_team</code>, the possible values of these 2 features are all the NBA teams.
  How can we "normalize" these features to be able to use them to create a deep network model (e.g. with tensorflow)?</p>
  
  <p>Any reference to read about techniques of modeling that are also very appreciated.</p>
  
Tags: <deep-learning><categorical-data>
Title: How to model categorical variables / enums?
UserDisplayName: Avraam Mavridis
ThreadText: # How to model categorical variables / enums?
  
  (Asked by: username_0 on 2018-09-01)
  
  I am new to the field and I am trying to understand how is possible to use categorical variables / enums?
  
  Lets say we have a data set and 2 of its features are `home_team` and `away_team`, the possible values of these 2 features are all the NBA teams.
  How can we "normalize" these features to be able to use them to create a deep network model (e.g. with tensorflow)?
  
  Any reference to read about techniques of modeling that are also very appreciated.
  
  **Tags:** deep-learning, categorical-data
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-09-01. Score: 5
  
  Authors use many different approaches.
  
  One approach is to have a different input neuron for each possible category, and then use a "1-hot" encoding. So if you have 10 categories, then you can encode this as 10 binary features.
  
  Another is to use some sort of binary encoding. If you have 10 categories, it is sufficient to use 4 neurons to represent all possible categories by using binary numbers.
  
  A third approach is to convert your categories to cardinal values, and then normalize them. This may be more effective if your categories really are cardinal (i.e. orderable). If there isn't a natural ordering to them though, this might lead to strange results or make the problem difficult to learn (since it ends up embedding non-linear relationships in the learning problem that don't need to exist).
  
  > **Comments:**
  > **username_1**: @DuttaA I agree. It has many of the same problems as a cardinal encoding (i.e. introducing non-linear patterns to learn). I have seen it used from time to time however.  
  
  ---
  
  ### Answer by username_2 on 2018-09-01. Score: 2
  
  A one-hot encoding, as described in [John's answer](https://ai.stackexchange.com/questions/7781/how-to-model-categorical-variables-enums/7783#7783), is probably the most straightforward / simple solution (maybe even the most common?). It is not without its problems though. For example, if you have a large number of such categorical variables, and each has a large number of possible values, the number of binary inputs you need for one-hot encodings may grow too large.
  
  > Lets say we have a data set and 2 of its features are home\_team and away\_team, the possible values of these 2 features are all the NBA teams.
  
  In this specific example, a different possible solution might be not to use the "identity" of a team as a feature itself, but try to find a number of (ideally numeric) features corresponding to that team.
  
  For example, instead of trying to encode "home\_team" in some way in your inputs, you could (if you manage to find the data you need to do this) use the following features (not really familiar with NBA, so not sure if all these make sense):
  
  * Win percentage of home\_team in recent X amount of time
  * Historical win percentage of home\_team against away\_team
  * Average points scored per match by this team
  * In football there's something like how many minutes per game a team is "in control" of the ball, is there something similar in NBA maybe?
  * etc.
  
  And then you can try to get a similar list of features for the away\_team.
  
  This kind of solution would work for your example, and maybe also for various other examples. It might not work in all cases of categorical features though, in some cases you'd have to revert to solutions like those in John's answer.
  
  
  ---
  
  