Target Encode High-Cardinality Advertiser IDs Without Leakage

Last updated: November 29, 2026

Quick Overview

You want to replace a high-cardinality advertiser ID feature with its historical conversion rate for a gradient boosted model. Explain why naive target encoding overfits and implement an out-of-fold, smoothed version.

Google
Machine Learning
Data Scientist
Google
November 29, 2026
Data Scientist
Technical Screen
Machine Learning
Medium

0

0

0 solved


You want to replace a high-cardinality advertiser ID feature with its historical conversion rate for a gradient boosted model. Explain why naive target encoding overfits and implement an out-of-fold, smoothed version.

Google Ads data has millions of advertisers and campaigns, and tree models cannot use raw IDs well. The interviewer checks that you know target encoding is a form of fitting that leaks labels unless done carefully, and that you can code a correct version.

What the Interviewer Expects
  • Explain naive target encoding and why it leaks each row's own label
  • Explain why rare categories make the leak severe
  • Use out-of-fold encoding so a row never sees its own label
  • Add smoothing toward the global prior with a strength parameter
  • Handle unseen categories at serving and keep train and serve encodings consistent
Key Topics to Cover
Target encoding
Label leakage
Smoothing
Out-of-fold
High-cardinality features
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
  • How would you encode categories in a time-ordered dataset instead of using random folds?
  • How do you choose the smoothing strength?
  • How does this compare with learning an embedding for the ID in a neural model?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Explore ML Interview Prep
Sample Answer
Clarify

Ask about the label (conversion per click), the number of advertisers and how many have few clicks, and whether training data is time-ordered, which would favor time-based encoding....

Approach

Show the leak, then fix it with out-of-fold statistics and Bayesian smoothing....


Submit Your Answer
Markdown supported