Encode Millions of Device Model IDs Without Target Leakage
Last updated: November 29, 2026
Quick Overview
A Microsoft Advertising click model has a categorical feature for device model with millions of distinct values, most seen only a few times. Compare one-hot, hashing, target encoding and learned embeddings, and explain how to use target encoding without leaking the label.
Microsoft
November 29, 20260
0
0 solved
A Microsoft Advertising click model has a categorical feature for device model with millions of distinct values, most seen only a few times. Compare one-hot, hashing, target encoding and learned embeddings, and explain how to use target encoding without leaking the label.
High-cardinality categoricals (device, publisher, query, advertiser) are everywhere in Microsoft Advertising and Bing models. Interviewers want to see trade-offs between encodings and a correct out-of-fold target encoding with smoothing.
What the Interviewer Expects
- Explain why one-hot is impractical and sparse at this scale
- Describe the hashing trick and its collision cost
- Give the smoothed target encoding formula
- Prevent leakage with out-of-fold or time-ordered encoding
- Mention embeddings for neural models and frequency thresholds for rare values
Key Topics to Cover
How to Approach This
- Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
- Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
- Feature engineering is often more impactful than model selection.
- Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
- Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
- How do you pick the smoothing strength?
- How does target encoding behave for a value first seen in production?
- When would you prefer embeddings over target encoding?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Explore ML Interview PrepSample Answer
Clarify
Model type matters: a gradient boosted tree benefits from dense numeric encodings, while a deep CTR model can learn embeddings. I would also ask how the training data is ordered in time, since the cli...
Approach
- One-hot: millions of sparse columns, fine for logistic regression with L1, poor for trees.
- Hashing: map to buckets, constant memory, handles unseen values, but collisions merge un...
Submit Your Answer
Microsoft Machine Learning Engineer Interview Guide
Interview process, tips, and preparation timeline