Foundations to Frontier
Tests
D. Classical Machine Learning › D0 Core Concepts (concept pages)

The Machine Learning Workflow, End to End

A model is a small part of a machine learning system. The workflow runs from framing the problem and defining success, through collecting, cleaning and splitting data, engineering features, choosing a baseline, training and tuning, evaluating honestly, to deploying, monitoring and retraining. This page walks through each stage, the artefacts it produces and the mistakes that commonly break it (leakage, unscaled features, missing-value handling, no baseline, no monitoring). In the exercises you build a complete workflow in NumPy, from raw CSV to a saved and reloaded model; then you measure how much each workflow step contributes to the final performance of a failure-prediction model.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A recipe, not just an oven

Baking a cake is more than the oven. You decide what cake you want, buy ingredients, throw away the bad eggs, measure everything the same way, bake, taste, and write down the recipe so you can bake it again. Machine learning is the same: the training algorithm is the oven, and most of the work, and most of the mistakes, happen before and after it.

Building a pipeline step by step
test accuracy on 1 500 new machines: 48.6% (always guessing the common class ≈ 50%) · training rows used: 500 of 500
The workflow is: frame the question → collect data → clean → split → engineer features (fitted on training data only) → train → evaluate against a baseline → deploy → monitor. Without scaling, the hours column (values up to 20 000) forces gradient descent to take tiny steps and the model barely learns; the indicator columns help because a missing temperature is itself a warning sign here.
Why engineers care

In industry and in mission operations, models fail far more often because of a broken workflow (leaked test data, a missing-value bug, a sensor recalibrated after deployment) than because of a poor algorithm. A reliable workflow is what makes a model trustworthy.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Which part of ML takes most of the work in practice?
  2. 2. In the demo, which step made the biggest difference?
  3. 3. Why write down the recipe (save the model and steps)?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The stages

  1. Frame the problem: what decision will the prediction support? Which metric matters, and what is the cost of each error? What does success look like, and what is the baseline (current practice or a trivial model)?
  2. Collect and understand the data: sources, units, sampling, label quality; exploratory analysis (C1.7).
  3. Clean: fix types, remove duplicates, handle missing values and outliers, align time zones and units.
  4. Split before any fitting: train / validation / test, respecting groups and time (D0.3, D0.4).
  5. Engineer features: scaling, encoding, transforms, domain features, all fitted on training data only (D0.12).
  6. Train baselines, then models; tune hyperparameters on validation data (D0.13).
  7. Evaluate once on the test set, with the right metric and uncertainty; analyse errors by segment.
  8. Deploy: package the preprocessing and the model together, version both (C7.5), and serve them.
  9. Monitor and retrain: watch input drift, prediction drift and performance; retrain on schedule or on alarm.
from sklearn.pipeline import make_pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
import joblib
pipe = make_pipeline(SimpleImputer(strategy="median", add_indicator=True), StandardScaler(), LogisticRegression())
pipe.fit(X_train, y_train); print(pipe.score(X_test, y_test))
joblib.dump(pipe, "model.joblib")              # preprocessing and model saved as one object
📝 Quick check (Level 1)
0/3 answered
  1. 1. When should you split the data?
  2. 2. A baseline is…
  3. 3. Why save preprocessing with the model?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

Artefacts and pitfalls per stage

Stage Artefact Common failure
framing metric, cost matrix, baseline optimising accuracy when errors have unequal costs
data data card / schema silent unit changes, label noise
split index files, seeds random split of grouped or time-ordered data
features fitted transformers fitting scalers or imputers on all data (leakage)
training model, config, logs no baseline; tuning on the test set
evaluation report with intervals a single number, no error analysis
deployment versioned pipeline different preprocessing in production (training–serving skew)
monitoring dashboards, alerts no drift detection

Missing values can carry information (a sensor fails when hot); an indicator column lets the model use it. Scaling matters for gradient-based and distance-based models: with features differing by 10⁴ in scale, the largest stable gradient step is set by the largest feature, so the others barely move.

🐍 Exercise 1: a complete workflow in NumPy
Parse a raw CSV with missing cells; split it; fit median imputation and standardisation on the training set only; train logistic regression by gradient descent; compare with a majority baseline; save the preprocessing state and model as JSON, reload them and check the predictions are identical.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Training–serving skew means…
  2. 2. Why add a 'was missing' column?
  3. 3. Unscaled features slow gradient descent because…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Making workflows reliable

  • Pipelines as code: scikit-learn Pipeline, DVC stages (C7.5), Airflow or Prefect for scheduled retraining.
  • Experiment tracking: log data version, code commit, parameters, metrics and artefacts (MLflow, Weights & Biases).
  • Tests for ML: schema checks on inputs, invariance tests (renaming a satellite does not change predictions), minimum-performance gates before deployment.
  • Monitoring: population stability index or KS tests on inputs, calibration checks, delayed-label evaluation; define retraining triggers.
  • Documentation: model cards and data sheets.

Interview questions. Walk through how you would build a churn or failure model. (Framing → data → split → baseline → features → model → evaluation → deployment → monitoring.) What would you do if offline accuracy is high but production performance is poor? (Check skew, leakage, drift, label delay.)

📝 Quick check (Level 3)
0/3 answered
  1. 1. Offline 95% accuracy but 70% in production; first suspect?
  2. 2. A model card documents…
  3. 3. Experiment tracking should record…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Which steps matter? An ablation

Exercise 1. On 400 machines with 10% missing cells, the full NumPy workflow reaches 0.73 test accuracy against a 0.50 majority baseline. Predictions are identical after saving to JSON and reloading, and a new reading with a missing value is handled by the stored imputer.

Exercise 2: adding one step at a time. Failure prediction with 600 training and 3 000 test machines; 10 random datasets. The data have temperatures missing more often when hot, a log-normal current reading whose effect is logarithmic, a feature in the tens of thousands, and three noise columns.

Pipeline Test accuracy Log-loss
majority baseline 0.496 0.694
drop incomplete rows, raw features 0.502 0.688
+ median imputation (raw scales) 0.501 0.685
+ standardisation 0.733 0.525
+ log of the skewed feature 0.742 0.510
+ missing-value indicators 0.765 0.483
+ L2 strength tuned on validation 0.765 0.484

Without scaling, the operating-hours column limits the stable gradient step to about 10⁻⁸, so 300 epochs barely move the model and it is no better than guessing. Standardisation alone adds 23 points. The log transform matches the true effect shape (+0.9 points). The indicators let the model use the fact that a missing temperature signals a hot machine (+2.3 points). Tuning regularisation changes nothing, because 600 examples and 9 features leave little to regularise. The steps that mattered were data handling, not the model.

🐍 Exercise 2 (research): an ablation of workflow steps
Generate failure data with informative missingness, mixed scales and a skewed feature; evaluate a majority baseline and logistic regression with rows dropped, then with imputation, standardisation, a log transform, missing indicators and validation-tuned L2 added one at a time; average accuracy and log-loss over 10 datasets.

The workflow in AI, robotics and aerospace

  • Predictive maintenance: telemetry → features → failure model → alerts, with retraining as hardware ages.
  • Perception models on robots: data collection campaigns, labeling, versioned datasets, on-device deployment and field monitoring.
  • Space missions: onboard models must be validated before upload; ground pipelines retrain with new downlinked data.
  • MLOps standards: CRISP-DM and modern MLOps practices formalise these stages.

References

  1. C. Shearer (2000). “The CRISP-DM model: the new blueprint for data mining.” Journal of Data Warehousing 5(4).
  2. D. Sculley et al. (2015). “Hidden technical debt in machine learning systems.” NeurIPS.
  3. E. Breck et al. (2017). “The ML test score: a rubric for ML production readiness and technical debt reduction.” IEEE Big Data.
  4. M. Mitchell et al. (2019). “Model cards for model reporting.” FAT*.
  5. A. Géron (2022). Hands-On Machine Learning with Scikit-Learn, Keras and TensorFlow, 3rd ed., chapter 2. O’Reilly.