Target Encode High-Cardinality Seller IDs Without Leaking the Label

Last updated: November 29, 2026

Quick Overview

A late shipment model uses seller ID, which has millions of values. Explain how to encode it for a gradient boosted tree model using target encoding, why naive target encoding leaks, and implement out-of-fold encoding with smoothing.

Amazon
Machine Learning
Machine Learning Engineer
Amazon
November 29, 2026
Machine Learning Engineer
Technical Screen
Machine Learning
Medium

0

0

0 solved


A late shipment model uses seller ID, which has millions of values. Explain how to encode it for a gradient boosted tree model using target encoding, why naive target encoding leaks, and implement out-of-fold encoding with smoothing.

Amazon marketplace models deal with enormous ID spaces: sellers, ASINs, brands and ZIP codes. The interviewer checks whether you can turn an ID into a useful feature without letting each row see its own label, and how you handle rare and unseen IDs.

What the Interviewer Expects
  • Compares one-hot, hashing, frequency, target encoding and learned embeddings
  • Explains self-leakage in naive in-sample target means
  • Implements out-of-fold encoding for training rows
  • Applies smoothing toward the global prior for rare IDs
  • Handles unseen IDs at serving time and keeps encodings time-consistent
Key Topics to Cover
target encoding
out-of-fold
smoothing
high-cardinality categoricals
label leakage
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 choose the smoothing strength?
  • How does this change when the data is a time series of shipments?
  • Would you add the seller's shipment count as a separate feature?
  • When would you switch to learned embeddings instead?
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 the label (shipment arrived after promise), the number of sellers and their size distribution, whether the model is retrained daily, and how new sellers should be scored....

Approach

One-hot with millions of columns is impractical for trees. Target encoding replaces the ID with the late rate for that seller. Computed in-sample, a seller with one shipment gets its own label as the ...


Submit Your Answer
Markdown supported