🎯 Hands-on Portfolio Deliverable. Feature engineering decides more leaderboard positions than model choice. This project proves you can build preprocessing that is correct (no leakage), robust (unseen categories don't crash), and measurable (ablate every transformation).
🏢 Business Scenario & Executive Prompt
FreshKart, an online grocer, forecasts next-week demand per SKU-store to cut both stockouts (lost margin) and overstock (spoilage). An intern's notebook scores R² 0.94 — computed with imputation and target-encoding fit on the full dataset. The head of DS asks you: "Rebuild the pipeline so the number is honest, then show me which features actually pay for themselves."
📋 Source Data & Input Schemas
freshkart_demand.csv — 180,000 rows (SKU-store-weeks; mock shape):
| column | dtype | description |
|---|---|---|
sku_id | str | 2,400 SKUs (high cardinality) |
store_id | category | 60 stores |
week | date | week start (78 weeks of history) |
price_inr | float | selling price (8% missing) |
promo_flag | 0/1 | promotion active |
category | category | 18 grocery categories |
units_sold | float | target: next-week units |
Expected shapes: strong promo lift; price_inr missingness correlates with new SKUs; demand is weekly-seasonal.
🎯 Required Deliverables
features_pipeline.py— importablebuild_pipeline()returning an unfitted sklearnPipeline; no data loading inside.pipeline.pkl— fitted pipeline artifact +feature_list.json(exact post-transform column contract).cv_scores.json— time-based CV scores: baseline (numeric-only) vs +encoding vs +target-encoding vs leaky reference.leakage_report.md— the leaky-vs-clean gap with an explanation of which step leaked and the structural fix.
🛠️ Step-by-Step Implementation Guide
- Time-based splits. Sort by week; expanding-window folds (train past → validate future). No shuffling — demand has a time axis.
- Baseline pipeline. Median-impute + scale numerics, one-hot low-cardinality cats, Ridge regression. Record CV MAE/R².
- Handle
sku_id. Never one-hot 2,400 levels: implement in-fold target encoding (smoothed means computed inside each training fold) or hashing. Show the dimensionality math. - Prove the leak. Deliberately fit one leaky variant (encoders/imputers on full data) and measure the optimism gap vs the clean pipeline.
- Ablate. Remove each feature group once; keep only groups that improve time-CV beyond noise. Document the keep/drop table.
- Harden.
handle_unknown="ignore", missing-price path for new SKUs, and a 1-row inference smoke test with an unseensku_id.
💻 Complete Runnable Starter Scaffold
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.linear_model import Ridge
NUM = ["price_inr", "promo_flag"]
CAT_LOW = ["store_id", "category"]
def build_pipeline() -> Pipeline:
pre = ColumnTransformer([
("n", Pipeline([("imp", SimpleImputer(strategy="median")),
("sc", StandardScaler())]), NUM),
("c", Pipeline([("imp", SimpleImputer(strategy="most_frequent")),
("oh", OneHotEncoder(handle_unknown="ignore"))]), CAT_LOW),
])
return Pipeline([("pre", pre), ("reg", Ridge(alpha=1.0))])
# In-fold target encoding for sku_id (sketch): compute smoothed means with
# statistics from the TRAIN fold only, inside each CV iteration — never globally.
# expanding-window CV: sklearn.model_selection.TimeSeriesSplit
🧪 Acceptance Criteria & Verification Checks
-
features_pipeline.pyimports cleanly;build_pipeline()returns an unfitted pipeline with no data I/O. -
cv_scores.jsonshows time-based CV for ≥ 3 variants plus a leaky reference with a documented optimism gap. -
leakage_report.mdnames the leaking step(s), explains the mechanism, and states the structural fix. - Unseen
sku_id+ missingprice_inrscore without exceptions;feature_list.jsonmatches transform output width.
📊 Evaluation Rubric (100 points — passing ≥ 80)
| # | Criterion | Points | What earns full marks |
|---|---|---|---|
| 1 | Modeling correctness | 25 | Right algorithm for the task; leakage-free splits/pipelines; metrics match the business decision; numbers reproducible |
| 2 | Code quality & reproducibility | 25 | Seeded RNG, re-runnable notebook/scripts, typed schemas, no hardcoded paths or magic numbers |
| 3 | Business reasoning & memo | 25 | Decision-oriented write-up with costed trade-offs; honest about uncertainty, limits, and risks |
| 4 | Visualization & communication | 25 | Labeled ROC/PR, calibration, SHAP or residual plots where relevant; figures referenced in the narrative |
📤 Submission Guidelines
- Upload your files (
.ipynb,.py,.pkl,.csv,.md,.png) via the file dropzone on this lesson. - Paste your public GitHub repo URL in the submission notes (repo must contain the same files + a 5-line
READMEwith the run command). - Name files exactly as listed under Required Deliverables — review checks filenames first.
- Passing score is 80/100. You may resubmit; the highest score counts.