KatInterview

Leak-Proof Preprocessing and Training Pipeline Design

Machine LearningModel answer
HardModel answerMachine Learningdata-leakagepreprocessingpipelines

Last updated

Design an end-to-end workflow that validates, cleans, splits, fits, and serves a model so that no statistic from held-out or future data influences training.

You are handed a tabular dataset and asked to build a workflow that turns raw records into a trained predictive model. The same workflow must later be applied, unchanged, to held-out evaluation data and to new records that arrive after deployment.

Describe the design of this workflow:

  • What each stage is responsible for, and in what order the stages run.
  • Where and how information leakage could creep in, and what you do to stop it.
  • What gets saved so that serving-time behaviour matches training-time behaviour.
  • How the workflow reacts to missing, malformed, or previously unseen values.

The schema, target, missingness patterns, and model family are intentionally not given. Pick a concrete illustrative scenario and state your assumptions. Let the actual data contract drive your cleaning choices. Do not simply discard every row with a missing value, and do not compute any preprocessing statistic on the full dataset before splitting.

Questions worth settling in your answer:

  • What is one observation, and are rows independent, grouped (for example, several rows per customer), or ordered in time?
  • Which columns are features, identifiers, labels, or information that would not exist at prediction time?
  • How are missing, invalid, duplicate, and unseen categorical values treated?
  • Which preprocessing quantities must be learned from training data only?

Hints

Hint 1

Start from the unit of prediction and the moment of prediction: what is known at that moment, and how are rows related (independent, grouped, or temporal)? That determines how you split.

Hint 2

Separate stateless steps (type coercion, schema checks, deterministic fixes) from stateful steps (imputation values, scaling parameters, category vocabularies, target encodings). Only the stateful ones need fitting, and they must be fitted on the training portion only.

Hint 3

Bundle preprocessing and model into one serializable object, and think about what happens when a request arrives with a missing column, a wrong type, or a category never seen in training.