One-Hot Encoding
ELI5 - The Vibe Check
Models are bad at math with words, so if a column says red, blue, or green, you can't just feed that in directly. One-hot encoding turns that single column into three new columns, is_red, is_blue, is_green, each a simple 1 or 0, so the model sees clean numbers instead of a category it has no idea how to compare.
Real Talk
One-hot encoding converts a categorical variable with n possible values into n binary columns, where exactly one column is set to 1 for each row and the rest are 0, avoiding the false sense of numeric order that would be implied by simply assigning integers to categories. It's a standard preprocessing step for algorithms that expect numeric input and can't natively interpret categorical features, though it can balloon the number of columns when a category has very high cardinality.
Show Me The Code
import pandas as pd
df = pd.get_dummies(df, columns=['color'], prefix='color')
# color_red, color_blue, color_green columns, each 0 or 1
When You'll Hear This
"Don't just assign 1, 2, 3 to the categories, that implies an order that doesn't exist, one-hot encode it." / "This column has 40,000 unique values, one-hot encoding it would blow up the feature space."
Related Terms
Feature Engineering
Feature engineering is the unglamorous, hugely important work of turning raw, messy real-world data into the specific columns a model can actually learn fr...
Machine Learning (ML)
Machine Learning is teaching a computer by showing it thousands of examples instead of writing out every rule.
Pandas
Pandas is the Python library that turns a spreadsheet-shaped pile of data into something your code can actually filter, group, join, and reshape in a coupl...
Random Forest
A random forest is what you get when you refuse to trust a single decision tree's opinion and instead grow hundreds of slightly different trees, each train...