KatInterview

End-to-End E-Commerce Purchase Intent Prediction Pipeline

Machine LearningModel answer
MediumModel answerMachine Learningdata-preprocessingfeature-engineeringcross-validation

Last updated

Design a robust data cleaning, pipeline, validation, and threshold-tuning strategy to predict session conversions evaluated on weighted F1 score.

You are tasked with creating an end-to-end machine learning pipeline to forecast whether a web browsing session ends in a commercial transaction (outcome). The dataset consists of numerical metrics (e.g., duration, page views, drop-off rates) and categorical/encoded indicators (e.g., user operating system, traffic source type, region, promotional flag).

Your pipeline will be evaluated on unseen test data using weighted F1-score.

Core Constraints & Rules

  1. Column Filtering: Any feature containing more than 50% missing values or possessing zero variance (a single unique value) across the training dataset must be discarded.
  2. Strict Data Leakage Prevention: All stateful data transformations (imputation statistics, scaling factors, category encodings, column selection decisions) must be fitted exclusively on training splits or inside cross-validation folds.
  3. Format Integrity: The final output file submissions.csv must map every test set id to a binary integer prediction outcome $\in {0, 1}$. No rows from the test set may be omitted.

Discuss your architectural decisions, data audit steps, leakage prevention strategies, metric optimization nuances, and provide a complete reference Python pipeline.

Hints

Hint 1

Identify domain-level bugs early: page counts cannot be negative, exit/bounce rates must lie within [0.0, 1.0], and sentinel values like -999 must be coerced to NaN before pipeline fitting.

Hint 2

Be cautious with imbalanced target metrics: standard minority-class F1 optimization differs from weighted F1. Aggressively pushing minority recall can harm overall weighted F1 by increasing false positives in the majority class.

Hint 3

Categorical integer fields like OS or browser codes represent nominal IDs, not ordinal numeric relationships. Treat them as categorical features and one-hot encode them.