Skip to content
ML Academy

Feature engineering and preprocessing · insight-0112

Do not give a linear model ordinal codes for unordered categories

Evidence type
practitioner heuristic
Difficulty
easy
Roles
Data scientist, Data analyst, ML engineer
Industries
aviation, banking

Summary: situation, action, reason, boundary

  1. Situation

    A nominal feature such as market or payment method is label-encoded as 0, 1, 2 and fed to a linear, kernel or distance model.

  2. Action

    Use one-hot (or target encoding) for nominal features in linear and distance models; reserve ordinal codes for truly ordered levels such as fare levels L < M < H.

  3. Reason

    A linear term imposes equal spacing and a monotone effect on the code values, which only make sense when order and spacing are real.

  4. Boundary

    Linear and logistic regression, SVMs, k-NN, k-means and neural networks without embeddings.

Symptom or risk

The model assumes intl-long is twice intl-short and forces one slope across arbitrary codes; reordering the codes changes predictions.

Exceptions

Tree models can split ordinal codes repeatedly, so arbitrary codes are often tolerable there, though native categorical support is usually better.

Trade-offs

One-hot adds columns; ordinal codes are compact but encode a false structure.

Pitfalls

Ordinal levels with unequal gaps; even true orders may need one-hot if spacing matters.

Lessons and concepts

Claims and their sources