Dummy Variable Encoding Basics
You'll learn how to convert categorical data into a numeric format that regression models can understand.
The Problem with Categories
Regression models work with numbers, not text labels. If you have a categorical variable like "City" with values ["Boston", "Chicago", "Seattle"], you can't just plug these names into a regression equation. The model needs numbers—but simply assigning 1, 2, 3 would wrongly imply that Chicago is "twice" Boston, which makes no sense.
The Solution: Binary Indicators
Dummy variable encoding creates separate binary (0/1) columns for each category. Each column acts as an "on/off switch" indicating whether an observation belongs to that category.
How It Works
For a categorical variable with k categories, you create indicator variables:
- Each dummy variable equals 1 if the observation belongs to that category
- Each dummy variable equals 0 otherwise
Example: If you have a "City" variable:
- Create
City_Boston(1 if Boston, 0 otherwise) - Create
City_Chicago(1 if Chicago, 0 otherwise) - Create
City_Seattle(1 if Seattle, 0 otherwise)
An observation from Chicago would have: City_Boston = 0, City_Chicago = 1, City_Seattle = 0.
Think of It Like Light Switches
Imagine a control panel with switches for each category. For any given observation, exactly one switch is "on" (set to 1), and all others are "off" (set to 0). This tells the regression model which group that observation belongs to without implying any mathematical relationship between categories.
Key Takeaway: Dummy variable encoding transforms categorical variables into binary (0/1) indicator columns, allowing regression models to handle categorical predictors while preserving their qualitative nature.