Label encoding, also called ordinal encoding, replaces each categorical value with an integer code. For example, Color values Red, Blue, and Green can become 0, 1, and 2. The codes are labels, not measurements: their numeric order and spacing are arbitrary. section 4.9 section 9.4.2
The technique is commonly used when categorical features must be made numeric for an outlier detector. It avoids the extra binary columns produced by one-hot encoding, but the resulting representation must match the detector’s assumptions. section 3.3.2 section 9.4.2
Interpret label-encoded values according to the downstream detector:
- Use ordinal encoding cautiously with distance-based detectors: arbitrary codes can create misleading distances between categories. section 9.4.2
- Use it more favorably with Isolation Forest, which can treat repeated category values as duplicate records and exploit category frequency. section 9.4.2
- Treat encoded categories as bins rather than ordered numeric measurements in HBOS; rare ordinal values contribute frequency information, not meaningful order. section 6.2
Department frequencies with Isolation Forest
Suppose a Department column contains 1,000 Sales records, 500 Marketing records, and 50 Engineering records, encoded as 0, 1, and 2. Isolation trees initially isolate category values similarly, then retain duplicate counts when nodes stop splitting. Engineering records require fewer estimated isolation steps and are therefore more likely to receive high outlier scores than common Sales records. section 9.4.2



