Chapter 2
From Raw Data to Deployed Model: The End-to-End ML Playbook
— Notes from Géron's Hands-On ML, 3rd ed.
The Full Workflow
Eight Steps, One Working System
Every ML project — regardless of domain or algorithm — follows this cycle. Click any step to expand its explanation for your current view mode.
Model Benchmarks
How the Models Compare
Training RMSE vs. cross-validation RMSE tells the real story. A model can look perfect on training data while failing badly on new examples — this gap is the overfitting signal.
| Model | Train RMSE | CV RMSE (10-fold) | Diagnosis |
|---|---|---|---|
| Linear Regression | ~68,688 | ~69,858 ± 4,182 | Underfitting |
| Decision Tree | 0 (!) | ~66,868 ± 2,061 | Severe overfitting |
| Random Forest | ~17,474 | ~47,019 ± 1,034 | Best so far (some overfitting) |
| Random Forest (tuned) | — | ~44,042 | Final model |
All RMSE values in USD. Lower is better. CV scores averaged over 10 non-overlapping folds.
Key Insights
What This Chapter Actually Teaches
Most ML work isn't modelling
The pipeline, imputation, encoding, scaling, and feature engineering dwarfs the model training step. A rough model with clean data beats a sophisticated model with dirty data.
RMSE vs MAE: pick your outlier tolerance
RMSE (L2 norm) punishes large errors heavily; MAE (L1 norm) treats all errors equally. For bell-shaped distributions, RMSE is preferred. In outlier-heavy data, MAE is more robust.
Stratify on what matters
Random sampling risks a skewed test set. Stratify on the most predictive continuous variable (income category here) to guarantee proportional representation across strata.
Zero training error is a warning sign
The DecisionTree scored RMSE=0 on training data — which looks perfect but means it memorised, not learned. Cross-validation exposes this: the same model scored ~67K on unseen folds.
Engineer before you model
bedrooms_ratio (total_bedrooms / total_rooms) correlated at r=-0.256 with price — far stronger than either raw component. Domain-informed feature combinations often matter more than algorithm choice.
Confidence intervals beat point estimates
A final RMSE of 41,424 sounds precise, but the 95% CI [39,574; 43,780] is what actually informs a launch decision. Point estimates hide the uncertainty that matters for risk management.
Pipeline Anatomy
The Preprocessing Pipeline in Full
The ColumnTransformer fans out to 7 sub-pipelines that each handle a different transformation class, then concatenates all outputs into a 24-feature NumPy array fed to the final estimator.
ratio_pipeline
Computes bedrooms_ratio, rooms_per_house, people_per_house via column division + StandardScaler
→ 3 features
log_pipeline
Log-transforms heavy-tailed columns (total_bedrooms, total_rooms, population, households, median_income)
→ 5 features
cluster_simil
KMeans(n=10) on lat/lon → Gaussian RBF similarity to each cluster centre (geographic encoding)
→ 10 features
cat_pipeline
SimpleImputer(most_frequent) + OneHotEncoder for ocean_proximity categorical attribute
→ 5 features
default_num_pipeline
SimpleImputer(median) + StandardScaler for remaining numerical column (housing_median_age)
→ 1 feature
Total output
24 features → RandomForestRegressor
Mental Models
Three Ideas Worth Keeping
The test set is your conscience
Touch the test set exactly once: at the very end, after all hyperparameter decisions are locked. Any adjustment made after seeing test results is implicitly fitting to that test set, invalidating it as an unbiased estimator of generalisation error. Report a confidence interval, not just the point RMSE.
Pipelines are reproducibility infrastructure
A fitted Scikit-Learn Pipeline encapsulates the exact transformation state (imputer medians, scaler statistics, encoder categories, cluster centres) learned from training data. When you call predict() on new data, all transformations apply automatically using training-set statistics — no manual preprocessing required, no leakage possible.
Model rot is the silent production killer
A model trained on 1990 census data will degrade as neighbourhoods gentrify, coastal restrictions evolve, and demographic patterns shift. Monitor input feature distributions for drift (μ/σ shifts, new categories in ocean_proximity), and instrument downstream proxy metrics. Automate periodic retraining with a performance gate before production swap.
HOML Reading Series · Ch.3 coming next