Overview
Label encoding assigns a unique integer to each category in a variable. For example, 'Red' = 0, 'Blue' = 1, 'Green' = 2.
When to Use
It is best used for ordinal data, where the categories have a natural order (e.g., 'Small' = 0, 'Medium' = 1, 'Large' = 2).
Risk
For non-ordinal data, models might incorrectly assume a mathematical relationship between the numbers (e.g., that 'Green' is 'greater than' 'Red'), which can lead to poor performance. In such cases, One-Hot Encoding is usually preferred.