Knowledge Maxxing
← Back to topic library
ML MaxxingIntermediate75 sec

One-hot encoding

One-hot encoding converts a categorical feature into several binary columns, one per possible category, each marking whether that category applies to a given example.

Prerequisite: Feature scaling

What matters

Most models expect numeric input and would otherwise misread category labels as having an order or magnitude, so one-hot encoding avoids implying a false ranking between categories.

Example

A 'color' feature with values red, blue and green becomes three separate 0/1 columns: is_red, is_blue, and is_green.

Common misconception

One-hot encoding does not work well for categorical features with thousands of possible values; it can produce an impractically large number of columns.

Recall question

Why can't most models directly use a text category label as a plain number?

Keywords and related concepts

one-hot encodingcategorical variablepreprocessingfeature engineering

Related topics

Feature engineering
ML MaxxingIntermediate
Feature scaling
ML MaxxingIntermediate