Categorical features and dimensionality
One-hot encoding of colors
Categorical features represent labels (for example, colors or cities), not continuous numbers.
To use them in many models, we often apply one-hot encoding: each category gets its own dimension with 0/1 values.
Example of code:
<?php
function encodeColor(string $color): array {
return [
$color === 'red' ? 1 : 0,
$color === 'green' ? 1 : 0,
$color === 'blue' ? 1 : 0,
];
}