HomeLearnCoursesHackathonsAccount
Feature Engineering for ML
Encoding and Scaling Raw Data · 1/2

Turning categories into numbers

Real-world data is rarely usable as-is. Most models are, at their core, doing arithmetic on numbers, so a column like 'color' with values red, green, and blue has no inherent numeric meaning a model can multiply or compare. Converting categorical values into a numeric form is called encoding. The most common approach, one-hot encoding, creates a separate 0/1 column for each category, so 'green' becomes a 1 in the green column and 0 everywhere else.

It's tempting to just assign red=1, green=2, blue=3 and call it done, but that introduces a fake ordering and a fake distance the categories don't actually have, it implies blue is somehow 'more' than red, which is meaningless. One-hot encoding avoids that by keeping categories independent, though it does mean a column with hundreds of unique categories turns into hundreds of new columns, which is its own tradeoff to manage.