One-hot encoding turns a categorical feature into numerical indicator features, making the categories usable by machine-learning models without assigning them an artificial numeric order. section 13.3 section 13.7
For each categorical feature:
- Create a separate binary feature for each category. section 9.3 section 13.3
- Mark whether each example belongs to each category; for a dog, cat, or bird feature, the dog example becomes yes, no, no. section 9.3
- Prefer these indicators to assigning categories numbers when that would imply an unintended order. section 13.3
Passenger data
Sex and port of embarkation are categorical features in the passenger dataset; one-hot encoding turns them into numerical features for a model. section 13.3
Figure 13.1 One-hot encoding our data to turn it all into numbers for the machine learning model to read. On the left, we have columns with categorical features such as gender or port of embarkment. On the right, we have turned these categorical features into numerical features.
Compare the categorical columns with their numerical indicator features. section 13.3












