How do you handle unseen categorical levels encountered during inference?

Quick Overview

Asks how a deployed model should treat categorical values at inference time that never appeared in its training data. It tests encoder fallbacks across one-hot, ordinal, target, embedding and hashing schemes, plus train/serve consistency and monitoring for drift.

How do you handle unseen categorical levels encountered during inference?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How do you handle unseen categorical levels encountered during inference? For example, a model trained with a `city` feature receives a city at serving time that never appeared in the training data. ```hint Go encoder by encoder One-hot, ordinal, target encoding, embeddings and hashing each react differently to a value they have never seen. ``` ```hint Check the training side Ask whether the model ever saw the fallback representation during training, and what weight it learned for it. ``` ### What a Strong Answer Covers - A defined fallback for unseen levels in place of an error or an arbitrary code - How that fallback differs across one-hot, ordinal, target encoding, embedding and hashing schemes - Training the model so the fallback bucket has a learned weight - Fitting encoders on training data only and shipping them with the model to avoid train/serve skew - Monitoring the rate of unseen levels in production ### Follow-up Questions - With one-hot `handle_unknown='ignore'`, what does a linear model predict for an unseen city, and when is that a poor default? - How do you pick the number of hash buckets, and what do collisions cost you? - How would you handle an ID feature where hundreds of new levels appear every day? - The unseen-level rate jumps from 2% to 30% overnight. What do you check first?

Overview: Asks how a deployed model should treat categorical values at inference time that never appeared in its training data. It tests encoder fallbacks across one-hot, ordinal, target, embedding and hashing schemes, plus train/serve consistency and monitoring for drift.

General logo
General
Nov 25, 2026
mediumMachine Learning EngineerOtherMachine Learning
0
0

How do you handle unseen categorical levels encountered during inference?

For example, a model trained with a city feature receives a city at serving time that never appeared in the training data.

What a Strong Answer Covers Guidance

  • A defined fallback for unseen levels in place of an error or an arbitrary code
  • How that fallback differs across one-hot, ordinal, target encoding, embedding and hashing schemes
  • Training the model so the fallback bucket has a learned weight
  • Fitting encoders on training data only and shipping them with the model to avoid train/serve skew
  • Monitoring the rate of unseen levels in production

Follow-up Questions Guidance

  • With one-hot handle_unknown='ignore' , what does a linear model predict for an unseen city, and when is that a poor default?
  • How do you pick the number of hash buckets, and what do collisions cost you?
  • How would you handle an ID feature where hundreds of new levels appear every day?
  • The unseen-level rate jumps from 2% to 30% overnight. What do you check first?