Answers.Body: <p>As with many <em>general</em> questions about how to represent features, or best learn from them, the answer is "it depends".</p>
  
  <ul>
  <li><p>If there is a natural sequence to the separate items, and that sequence is informative somehow for the prediction, then the classes may work best as a single feature which takes discrete values, scaled to the network. A good example might be predicting house prices where one of the features is property tax bands (in locations which have these such as UK Council Tax).</p></li>
  <li><p>If the classes have no natural sequence to them relating to the problem, then one-hot-encoding is usually a better interpretation. An example of this might be predicting the price of a car based on the manufacturer.</p></li>
  </ul>
  
  <p>In both cases, a neural network with enough layers and connections - and enough data - could resolve a more difficult representation, and make little effective difference between the representations in practice. However, if you know something useful about the feature, it is normal to choose the most "natural" representation based on that knowledge, and you will often see a small improvement by making the correct choice. In the first case, the neural network can benefit from requiring less parameters, and learn more efficiently.</p>
  
  <p>If you are not sure, then choosing one-hot versus a single scaled input should be an experiment which you perform as part of your hyper parameter tuning, along with any other feature engineering that you are not sure of.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-21T13:08:38.553Z
Answers.LastActivityDate: 2019-04-21T13:08:38.553Z
Answers.UserDisplayName: Neil Slater
Body: <p>Let's say you have an input which can take one of 10 different unique values. How would you encode it?</p>
  
  <ol>
  <li><p>Have input length 10 and one-hot encode it.</p></li>
  <li><p>Have 1 input but normalise the value between the input range.</p></li>
  </ol>
  
  <p>Would the end result be the same?</p>
  
Tags: <neural-networks><machine-learning><ai-design>
Title: How should I encode a categorical input?
UserDisplayName: BigBadMe
ThreadText: # How should I encode a categorical input?
  
  (Asked by: username_0 on 2019-04-21)
  
  Let's say you have an input which can take one of 10 different unique values. How would you encode it?
  
  1. Have input length 10 and one-hot encode it.
  2. Have 1 input but normalise the value between the input range.
  
  Would the end result be the same?
  
  **Tags:** neural-networks, machine-learning, ai-design
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-04-21. Score: 3 | Accepted answer
  
  As with many *general* questions about how to represent features, or best learn from them, the answer is "it depends".
  
  * If there is a natural sequence to the separate items, and that sequence is informative somehow for the prediction, then the classes may work best as a single feature which takes discrete values, scaled to the network. A good example might be predicting house prices where one of the features is property tax bands (in locations which have these such as UK Council Tax).
  * If the classes have no natural sequence to them relating to the problem, then one-hot-encoding is usually a better interpretation. An example of this might be predicting the price of a car based on the manufacturer.
  
  In both cases, a neural network with enough layers and connections - and enough data - could resolve a more difficult representation, and make little effective difference between the representations in practice. However, if you know something useful about the feature, it is normal to choose the most "natural" representation based on that knowledge, and you will often see a small improvement by making the correct choice. In the first case, the neural network can benefit from requiring less parameters, and learn more efficiently.
  
  If you are not sure, then choosing one-hot versus a single scaled input should be an experiment which you perform as part of your hyper parameter tuning, along with any other feature engineering that you are not sure of.
  
  
  ---
  
  