learn-classification-regression-with-phoebe / Session 10 of 10
Learn Classification & Regression with Phoebe · Session 10 of 10

Capstone: the bake-off

Everything meets everything. Nine sessions of algorithms line up for two honest leaderboards - one for who converts, one for how big the order is - each candidate carrying the settings you tuned by cross-validation in session 9, each scored exactly once on the held-out test set. Then the part that makes you employable: writing it up like an analyst, in dollars before scores, as a model card a stakeholder can act on. The surprise ending is the whole point of the course - on this data, the humble linear models win both events, and you will be able to say precisely why.

🔴 Capstone Builders · DA / DE / DS Python · scikit-learn 45 min
0-3 · Setup 3-15 · The rules 15-40 · Run + present 40-45 · What's next
Part 0

The moment the course has been building toward

You have met the whole supervised zoo and watched each animal face the Lumen data one at a time. Today they compete side by side, under one fair set of rules, and you deliver a verdict the way a working analyst does - not "logistic scored 0.69" but "we can rank buyers well enough to prioritise the top decile, and here is the dollar case." The bake-off is a capstone in the real sense: nothing new to learn, everything to put together.

Live - built in session Self-study - run after ★ The one big idea The case: Lumen Skincare
★ What you walk out with today Two honest leaderboards (classification by ROC-AUC, regression by R² and dollars), a model card per finalist you could hand to a stakeholder, the analyst's habit of leading with the business number, and a clear-eyed map of the four courses that turn this foundation into an edge.
Part 1 · the rules

How to run a fair bake-off 6 min live

A comparison is only worth as much as its fairness. Three rules carry over from session 9 and become law today: candidates enter with the settings cross-validation chose (no last-minute fiddling), every candidate is scored on the same held-out test set, and that test set is touched exactly once. Then the reporting rule from intro-ml: translate the metric into money before you say it out loud.

LiveThe leakage checklist - one last pass3 min▶

Before any number counts, confirm the pipeline is honest. This is the checklist that separates a real result from a lie you will discover in production:

  • Every transformer (scaler, one-hot encoder) lives inside the Pipeline, so it is fit on train folds only - never on the full data.
  • The train/test split happened once, up front, with random_state=42 and stratify=y on the classification task.
  • No feature was computed from the target or from information unavailable at prediction time.
  • The test set has not been used to choose anything - not a model, not a hyperparameter, not a threshold.
The one-line test: if you cannot point at exactly where each transformer was fit, assume leakage and re-check. A test score you cannot defend is worse than no score.
LiveWhat "winning" actually means3 min▶

The top of the leaderboard is necessary, not sufficient. A model wins the bake-off when it clears three bars at once:

  • Best (or tied-best) test score - it generalises.
  • Explainable - you can tell a stakeholder why it predicts what it predicts. A readable coefficient beats a marginally higher score you cannot narrate.
  • Shippable - it trains, scores, and monitors within the constraints you actually have (latency, memory, retraining cadence).
Real worldA team once shipped the model that won their offline leaderboard by half a point of AUC - a gradient-boosted ensemble no one could explain. When it drifted three months later, nobody could say why, and it was quietly rolled back to the logistic model it had replaced. Explainable and shippable are not consolation prizes.
Part 2 · the results

Two leaderboards, one honest surprise 14 min live

Here is the whole course on two tables. Each candidate ran once on the held-out test set with its session-9 settings. Read them slowly - the ranking is the lesson, and the lesson is that sophistication did not win.

Classification - test ROC-AUC logit 0.69 LinSVC 0.69 tree d5 0.66 GNB 0.66 kNN 101 0.64 RBF 0.56 0.5 = coin flip; bars start at 0.5 Regression - test R² linear 0.59 tree d4 0.54 kNN 25 0.46 mean 0.00 baseline = predict the mean; RMSE ~$40 On log-linear data the linear family wins both events - knowing WHY is the whole course.
🔍 Click to zoom - the two final leaderboards
LiveReading the classification podium5 min▶

Full features, test ROC-AUC:

ModelTest ROC-AUCWhy it landed here
Logistic regression~0.69a straight boundary is the right shape for this data
Linear SVM (LinearSVC)~0.69same straight-boundary family - it ties, and that is the tell
Decision tree (depth 5)~0.66axis-parallel cuts approximate the line, a little worse
Gaussian naive Bayes~0.66a fast, wrong-but-useful probability model
kNN (k=101, scaled)~0.64local voting in a 20-dimensional one-hot space, blurred
SVC RBF (default)~0.56an untuned curved boundary on data that wants a line

The pattern behind the ranking is not "fancier is better" - it is boundary-shape match beats algorithm sophistication. Logistic and LinearSVC tie because they draw the same object: a straight cut through feature space. When the true signal is (log-)linear, that is exactly the right hypothesis, and nothing more elaborate can do better by being more elaborate.

LiveReading the regression podium4 min▶

On the 1,306 buyers, test R² and RMSE:

ModelTest R²RMSERead
Linear regression~0.59~$25the workhorse wins
Decision tree (depth 4)~0.54-rectangles approximating a ramp
kNN regressor (k=25)~0.46-neighbor-averaging, over-smoothed
Mean baseline0.00~$40the floor every model must beat

The regression story rhymes with the classification one. Order value rises smoothly with prior spend (the r ~ 0.6 the statistics course fit), so a straight line captures it best. The tree carves that smooth ramp into steps and loses ground; kNN averages across neighbours and blurs it. Same lesson, second task: match the model to the shape of the truth.

Self-studyWhat would flip the ranking3 min▶

The linear family did not win because linear models are generally best - they won because the Lumen generator is log-linear by construction. Change the data and the podium reshuffles:

  • Interactions and nonlinearity - if converting depended on "returning customers on mobile after 9pm," trees and gradient-boosted ensembles would pull ahead. That is the terrain of learn-ensemble-methods.
  • Better features - a ratio, a rolling average, or a well-chosen interaction can lift every model at once. That is learn-feature-engineering.
  • A curved boundary - on the two-moons data in the explorer, the RBF kernel that lost here wins comfortably. No free lunch.
Part 3 · the write-up

Tell it like an analyst 10 min live

A number without a card is a rumour. The last skill of the course is packaging: a model card that a colleague can read in two minutes and act on, and a headline that leads with dollars, not decimals. This is what gets a model shipped.

The model card - eight fields a stakeholder can act on TASK + DATA convert · Lumen · seed 42 FEATURES 7 columns, one-hot + scaled TUNED SETTINGS chosen by 5-fold CV CV SCORE 0.706 +/- 0.010 TEST SCORE ROC-AUC ~0.69, once BUSINESS READ ranks buyers for the top decile FAILURE MODES rare-event base rate; proba needs a threshold OWNER + REVIEW DATE who maintains it, when it is re-checked Fill every field once and the model stops being a notebook artifact and becomes a decision others can trust.
🔍 Click to zoom - the eight fields of a model card
LiveDollars before scores3 min▶

The single habit that makes a data person sound senior: translate the metric into money before you say the metric. Two examples straight from these leaderboards:

  • Regression: not "R² is 0.59" but "our order-value model is off by about $25 on a typical order, against a $40 miss if we just guessed the average."
  • Classification: not "ROC-AUC is 0.69" but "we rank buyers well enough that the top-scoring tenth of sessions is roughly two to three times richer in real buyers than a random tenth - so target them first."
Real worldThe Lumen analyst who took the order-value model to the CFO did not open with R². She said "$25 off, versus $40 doing nothing" and got the budget in one meeting. Dollars land; decimals do not.
LiveThe recommendation4 min▶

Given the two leaderboards and the three bars of winning, the call is clear:

  • Ship logistic regression for conversion. Tied-best AUC (~0.69), coefficients that read as odds ratios a marketer understands (email x4.1, returning x2.8), and millisecond scoring. LinearSVC ties it but gives no probabilities - logistic wins on explainability.
  • Ship linear regression for order value. Best R² (~0.59), coefficients denominated in dollars, and an honest "$25 vs $40 baseline" headline.
  • The fancy models lost with dignity. The RBF kernel and deep trees were not broken - they were the wrong hypothesis for log-linear data. Keep them in your kit for the day the data curves.
Self-studyBecause models drift2 min▶

Shipping is the start of the model's life, not the end. Conversion rates shift with seasons and campaigns, and a model trained on last quarter can quietly decay. The monitoring-and-drift lifecycle - what to watch, when to retrain - is covered from the leader's angle in intro-ml session a6. The model card's "review date" field exists precisely so that decay has an owner.

Part 4 · the road on

Where you go from here 4 min live

You now speak algorithm - you can name the shape each model bets on, tune it, compare it fairly, and present the result. Four sibling courses turn that fluency into an edge.

learn-feature-engineering - the highest-leverage skill in tabular ML. Better inputs lift every model on both leaderboards at once; this is usually where real gains come from, not fancier algorithms.

learn-ensemble-methods (XGBoost & LightGBM) - the tabular champions. When the truth has interactions and nonlinearity that beat a straight line, gradient-boosted trees are what win in practice.

learn-model-evaluation - deeper judging: calibration, cost-sensitive thresholds, and the metrics beyond AUC that a high-stakes decision needs.

learn-experimentation (live now) - the leap from predicting to causing. Every model here answers "what will happen"; experimentation answers "what happens if we change something." The natural next rung.

★ The through-line: statistics gave you the math, intro-ml gave you the workflow, this course gave you the algorithms. You are no longer someone who calls .fit() and hopes - you are someone who chooses, and can say why.
Build-along

Run the bake-off, write the card ★ 20 min · everyone builds

Load both tasks, run every session-9-tuned pipeline exactly once on the held-out test set, print both leaderboards, and emit one model card. This is the script you keep and re-run for every future project.

Assemble the finalists. Each candidate is a full Pipeline carrying the settings CV chose in session 9 - no retuning here.

Fit on train, score once on test. One loop, one roc_auc_score (or r2_score) per model. The test set is spent now, for the first and only time.

Print both leaderboards sorted. The ranking should match the tables above within library jitter.

Emit a model card. One dict per finalist, dumped as readable text - the artifact you hand a stakeholder.

bakeoff.py - the leaderboard you now fully understandimport pandas as pd from sklearn.model_selection import train_test_split from sklearn.compose import ColumnTransformer from sklearn.preprocessing import OneHotEncoder, StandardScaler from sklearn.pipeline import Pipeline from sklearn.linear_model import LogisticRegression, LinearRegression from sklearn.tree import DecisionTreeClassifier from sklearn.neighbors import KNeighborsClassifier from sklearn.naive_bayes import GaussianNB from sklearn.svm import LinearSVC from sklearn.metrics import roc_auc_score, r2_score, mean_squared_error df = pd.read_parquet("lumen_sessions.parquet") cat = ["channel", "device", "new_vs_returning", "product_category"] num = ["pages_viewed", "session_hour", "prior_30d_spend"] prep = ColumnTransformer([ ("cat", OneHotEncoder(handle_unknown="ignore"), cat), ("num", StandardScaler(), num)]) # ---- classification bake-off ---- X, y = df[cat + num], df["converted"] Xtr, Xte, ytr, yte = train_test_split( X, y, test_size=0.25, random_state=42, stratify=y) clf = { "logistic": LogisticRegression(max_iter=2000), "LinearSVC": LinearSVC(max_iter=5000), "tree d5": DecisionTreeClassifier(max_depth=5, random_state=42), "GaussianNB": GaussianNB(), "kNN k=101": KNeighborsClassifier(n_neighbors=101)} print("CLASSIFICATION (test ROC-AUC, once)") for name, model in clf.items(): pipe = Pipeline([("prep", prep), ("model", model)]).fit(Xtr, ytr) # LinearSVC has no predict_proba - use the decision function to rank s = (pipe.decision_function(Xte) if name == "LinearSVC" else pipe.predict_proba(Xte)[:, 1]) print(f" {name:11s} {roc_auc_score(yte, s):.2f}") # logistic 0.69 · LinearSVC 0.69 · tree 0.66 · GaussianNB 0.66 · kNN 0.64 # ---- regression bake-off (buyers only) ---- buyers = df[df.converted == 1] Xr, yr = buyers[cat + num], buyers["order_value"] Xrtr, Xrte, yrtr, yrte = train_test_split( Xr, yr, test_size=0.25, random_state=42) reg = Pipeline([("prep", prep), ("model", LinearRegression())]).fit(Xrtr, yrtr) p = reg.predict(Xrte) rmse = mean_squared_error(yrte, p) ** 0.5 print(f"\nREGRESSION linear R2 {r2_score(yrte, p):.2f} RMSE ${rmse:.0f}") # R2 ~0.59 RMSE ~$25 (vs a predict-the-mean baseline of ~$40) # ---- the model card ---- card = { "task": "predict `converted` on Lumen (seed 42)", "model": "LogisticRegression, full features, one-hot + scaled", "cv_score": "ROC-AUC 0.706 +/- 0.010 (5-fold, on train)", "test_score": "ROC-AUC 0.69 (held-out, scored once)", "business_read": "ranks buyers - target the top-scoring decile first", "failure_modes": "3% base rate: pick a threshold by cost, not 0.5", "owner": "you · review each quarter"} for k, v in card.items(): print(f"{k:14s}: {v}")
This is the deliverable, not the notebook. The leaderboard proves the choice; the card makes it shippable. Keep this script - swap the dataset and the candidate dict, and you have a fair bake-off for any future project.
Homework

Finish the course strong ◐ 40 min

Check yourself

Three questions before you go 🎯 ◐ 90 seconds

1 · Why does every candidate get exactly one pass over the test set?

The moment you use the test set to choose anything, it stops being an honest estimate of new-data performance. Tuning happened on cross-validation in session 9; the test set is touched once, at the end, and never again.

2 · Logistic regression and LinearSVC tied at ~0.69 AUC. What does the tie tell you?

Both are linear classifiers: they fit a straight boundary in feature space. When that shape matches the truth, both hit the same wall, and no amount of algorithmic difference between them changes it. Boundary shape, not brand name, sets the ceiling.

3 · How should you present the regression winner to a stakeholder?

Dollars before scores. A decision-maker acts on "$25 versus $40," not on 0.59. Leading with the business translation is the habit that separates a report that gets shipped from one that gets filed.

Source material

What this session covers

The capstone introduces no new source content - it synthesises the nine sessions into a fair comparison and an analyst's write-up. The threads pulled together:

✓The zoo map and two familiesfrom Session 1
✓The lines and their losses - linear, logistic, gradient descentSessions 2-4
✓The local and probabilistic animals - kNN, naive BayesSessions 5-6
✓Trees and margins - depth, pruning, kernelsSessions 7-8
✓The fair-comparison protocol - CV to tune, test onceSession 9
◐Certificates, graded labs, and lecture videosremain with the official providers

Session 10 cheat sheet · pin this

Classification podiumlogistic ~0.69 = LinearSVC ~0.69 > tree(d5) ~0.66 = GaussianNB ~0.66 > kNN(101) ~0.64 > RBF-default ~0.56. Test ROC-AUC.
Regression podiumlinear ~0.59 / ~$25 > tree(d4) ~0.54 > kNN(25) ~0.46 > mean baseline 0 / ~$40. Test R² and RMSE.
Why linear wonthe Lumen generator is log-linear, so a straight boundary is the right shape. No free lunch - curved data would flip it.
The model cardtask + data, features, tuned settings, CV score +/- spread, test score, business read, failure modes, owner + review date.
Dollars before scores"$25 off vs a $40 baseline" beats "R² 0.59" in every review. Translate the metric before you say it.
The four bridgesfeature-engineering (better inputs), ensembles (nonlinear champions), model-evaluation (deeper judging), experimentation (cause, not prediction).