One-hot encoding replaces each categorical feature with one binary indicator column per unique value. A row receives 1 in the column matching its category and 0 in the others, while existing numeric features remain unchanged. section 4.9
Encoding categorical features
A Color column containing Red, Blue, and Green becomes Color_Red, Color_Blue, and Color_Green. For baseball positions, get_dummies() creates columns such as Position_Catcher and Position_Outfield; each row has exactly one 1 across the position columns. section 4.9
One-hot encoding is commonly useful for outlier detection when a categorical feature has low cardinality, and it works well with many detectors. However, high-cardinality features create many columns. This can give those features disproportionate influence in IsolationForest and overrepresent categorical differences in distance calculations. section 9.4.1
Encoding choice depends on the dataset, detector, and outliers being sought. Ordinal encoding may be preferable for IsolationForest, while one-hot encoding can make the contribution of individual category values easier to inspect with feature-importance methods. section 9.4 section 13.2.1
Table 9.12 Dataset after one-hot encoding (view table figure)
| Row |
Red |
Blue |
Green |
White |
Yellow |
Big |
Small |
|---|---|---|---|---|---|---|---|
| 1 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
| 2 |
0 |
1 |
0 |
0 |
0 |
0 |
1 |
| 3 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
| 4 |
0 |
1 |
0 |
0 |
0 |
1 |
0 |
Inspect a compact table showing how color and size categories become binary columns, including the unchanged one-hot pattern for each row. section 9.4.1





