A model needs numbers, but a category such as a diamond’s cut or its place of origin may be written as a word. One-hot encoding turns each possible category into its own 0-or-1 indicator. Picture a row of switches: exactly one is on for each example. section 8.9
Encode a diamond’s cut
Make five columns: Fair, Good, Very Good, Premium, and Ideal. For a Good cut, put 1 in Good and 0 in the other four. Each diamond gets one active cut column. section 8.9
Table 8.6 The diamond dataset with one-hot-encoded values
|
Carat |
Cut: Fair |
Cut: Good |
Cut: Very Good |
Cut: Premium |
Cut: Ideal |
|
| 1 |
0.30 |
0 |
1 |
0 |
0 |
0 |
| 2 |
0.41 |
0 |
0 |
0 |
0 |
1 |
| 3 |
0.75 |
0 |
0 |
1 |
0 |
0 |
| 4 |
0.91 |
0 |
0 |
0 |
0 |
0 |
| 5 |
1.20 |
1 |
0 |
0 |
0 |
0 |
| 6 |
1.21 |
0 |
1 |
0 |
0 |
0 |
| 7 |
1.31 |
0 |
0 |
0 |
1 |
0 |
| 8 |
1.50 |
0 |
0 |
0 |
1 |
0 |
| 9 |
1.74 |
0 |
0 |
1 |
0 |
0 |
| 10 |
1.83 |
1 |
0 |
0 |
0 |
0 |
| 11 |
1.96 |
1 |
0 |
0 |
0 |
0 |
| 12 |
1.19 |
0 |
0 |
0 |
1 |
0 |
Compare the Cut columns across diamond rows to see how the active indicator moves with the category. section 8.9
This is especially useful when categories have no meaningful order. Numbering diamond origins could suggest that one location ranks above another; separate indicators avoid that suggestion. Label encoding is better reserved for ratings where the numbers carry meaningful rank. section 8.9
Encode nearby block states
An artificial neural network can represent one block as [1, 0, 0, 0] for empty or [0, 0, 1, 0] for pedestrian. Four indicators for each of eight adjacent blocks produce 32 inputs. The larger input lets the network learn different effects for distinct states without treating them as a numeric scale. section 10.11












