KatInterview

Next-Month Purchase Model: Leak-Free Pipeline and AUC Evaluation

Machine LearningModel answer
MediumModel answerMachine Learninggradient-boostingscikit-learncross-validation

Last updated

Build a reproducible stratified-split pipeline with a gradient-boosted classifier for repeat-purchase prediction, report held-out AUC, and propose two ways to improve generalization.

Context

You have a cleaned table of retail customers. Each row describes one customer, and the binary label says whether that customer placed at least one order during the following month. Your job is to build a classifier for this label and judge it honestly.

Tasks

  1. Divide the data into training and test sets in an 80/20 ratio, stratifying on the label so both sets keep the same share of buyers.
  2. Create a single reproducible preprocessing-plus-model workflow in which numeric columns are standardized and categorical columns are one-hot encoded.
  3. Fit a gradient-boosted tree classifier (XGBoost or LightGBM) and report the AUC on the held-out test set.
  4. Suppose that AUC turns out to be disappointing. Name two techniques you would apply to improve how well the model generalizes, and explain which problem each one targets.

What to cover in your answer

  • Why and where you split, and what is allowed to see which rows.
  • How the pipeline prevents information from the test set leaking into preprocessing.
  • How you obtain AUC (probabilities vs. hard predictions) and how you would use cross-validation.
  • How you would diagnose the cause of a low score before choosing a remedy.
  • Any leakage risks specific to predicting future behavior from historical data.

Include code (scikit-learn style is fine) and state the complexity or cost considerations where relevant.

Hints

Hint 1

Everything that learns from data (scaler, encoder, model) should be fit on training rows only; a Pipeline with a ColumnTransformer enforces this automatically, and OneHotEncoder needs a setting for categories it has never seen.

Hint 2

AUC is rank-based, so compute it from predict_proba, not predict. Compare train, cross-validation, and test AUC to tell overfitting (big gap) from weak features (all low) and from leakage (suspiciously high).

Hint 3

For improvements, pair each technique with a diagnosis: regularization and tuned hyperparameters for variance, and time-aware behavioral features computed only from data before the cutoff date for bias.