Encode High-Cardinality Merchant IDs Without Target Leakage

Last updated: November 29, 2026

Quick Overview

A fraud model has a merchant id feature with about two million distinct values, most seen only a few times. Compare encoding options, explain how target encoding leaks if done naively, and describe a safe implementation.

Capital One
Machine Learning
Machine Learning Engineer
Capital One
November 29, 2026
Machine Learning Engineer
Technical Screen
Machine Learning
Medium

0

0

0 solved


A fraud model has a merchant id feature with about two million distinct values, most seen only a few times. Compare encoding options, explain how target encoding leaks if done naively, and describe a safe implementation.

Merchant identity is one of the most predictive signals in Capital One's card fraud models (compromised merchants, card-testing sites), but it is extremely high cardinality. The interviewer checks that you know encoding options and, especially, how to do target encoding without leaking labels into training rows.

What the Interviewer Expects
  • Rules out one-hot encoding for this cardinality and explains why
  • Describes frequency, hashing, target and embedding encodings
  • Explains leakage from computing target means on the same rows
  • Uses out-of-fold or time-ordered encoding with smoothing
  • Handles unseen merchants at serving time
Key Topics to Cover
target encoding
high cardinality
leakage
smoothing
embeddings
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 a merchant that appeared for the first time today?
  • How would fraudsters exploit a merchant risk feature?
  • How would you keep encodings consistent between training and the real-time scorer?
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

Fraud rate overall is about 0.1%. Most merchants have under 50 transactions, a few large ones have millions. The scorer runs in real time, so whatever encoding we choose must be computable from a feat...

Approach

Options:

  • One-hot: two million sparse columns, no generalization to rare merchants. Rejected.
  • Frequency encoding: cheap and leak-free; captures size, not risk.
  • Hashing into 2182^{18} buckets: boun...

Submit Your Answer
Markdown supported