Which supervised model families require explicit encoding of categorical inputs?

Last updated 14 November 2026

Any model that computes with numeric arithmetic on inputs needs categories encoded: linear/logistic regression, SVMs, k-NN, and neural networks. Some tree implementations (LightGBM, CatBoost, sklearn HistGradientBoosting) and Naive Bayes can consume categories natively, while classic sklearn trees still need numeric input.

  • Linear and logistic regression, and GLMs: Label codes (0, 1, 2) would impose a false order and equal spacing, so use one-hot encoding (dropping one level if unregularized, to avoid collinearity).

  • Distance and kernel models (k-NN, SVM): Distances need numeric vectors. One-hot encoding plus scaling is typical, or a categorical-aware metric (e.g. Hamming or Gower distance).

  • Neural networks: Use one-hot for low-cardinality features and learned embeddings (nn.Embedding) for high-cardinality ones like user or item IDs.

  • Tree models: it depends on the implementation:

    • Native support: LightGBM (categorical_feature), CatBoost (ordered target statistics), and HistGradientBoosting (categorical_features), which split on subsets of categories.

    • sklearn DecisionTree and RandomForest need numeric input. Ordinal encoding often works acceptably here because trees can isolate codes with multiple splits.

  • Naive Bayes: Categorical NB models per-category frequencies directly (CategoricalNB still expects integer codes, but no one-hot expansion is needed).

  • High cardinality: one-hot explodes dimensionality, so consider target encoding (computed out-of-fold to avoid leakage), hashing, or embeddings.

  • https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html
  • https://scikit-learn.org/stable/auto_examples/release_highlights/plot_release_highlights_0_24_0.html
  • https://scikit-learn.org/1.2/auto_examples/release_highlights/plot_release_highlights_0_24_0.html
All Supervised Learning interview questions