Skip to chapter content
navan✳THE BUILD LABMACHINE LEARNING / GUIDE
0/28 read
CHAPTER 28 / 28 · RESPONSIBLE SYSTEMS

A complete way to reason about ML.

Bring task, data, baseline, evaluation, model choice, and deployment into one coherent story.

BY NAVAN SAMILONG READTHEORY FIRST
01 / FROM THE BEGINNING

Start with the meaning.

The first question in a machine learning project is not which algorithm to import. It is what decision the prediction will support and when that decision occurs. A useful task statement names the input available at that moment, the target whose answer can later be observed, the population of cases, and the cost of mistakes. Without this statement, even an excellent test score can answer the wrong question.

The second question is whether the data can support that task. Rows need reliable identities, feature meanings, units, collection times, and labels. Missing groups or outcomes cannot be repaired by a model with more parameters. A small descriptive analysis can reveal duplicates, impossible values, rare categories, and changes across time. A baseline then establishes whether learning from the proposed features improves on a simple rule.

02 / THE MODEL

How the idea works.

A complete development procedure chooses a split that represents future use, fits preprocessing only on training data, compares candidate models through validation or cross-validation, and keeps a final test set outside those choices. Metrics should describe distinct error types, subgroup behavior, and uncertainty in the estimate. If the model is tuned many times against one validation set, the final result can become optimistic even when each individual step looked reasonable.

The chosen model is not necessarily the one with the largest single score. Consider the baseline gap, stability across folds and groups, cost of false alarms and misses, latency, memory, explanation needs, maintenance burden, and whether its required features will be available. A simple model with a clear failure mode can be a stronger product choice than a complex model with a tiny apparent improvement.

Deployment extends the same reasoning. Package the fitted preprocessing and predictor together. Validate live inputs, record artifact versions, monitor missingness and score changes, evaluate outcomes as they arrive, and define a fallback. Revisit the original task as the world changes. The system is successful when it supports better decisions in its intended setting, not when a notebook cell prints an attractive number.

EXAMPLESLEARNINGMODELPREDICTIONknown answerslearned rulenew case
Examples and known answers shape a model; new inputs receive predictions that can later be checked.
03 / PYTHON, EXPLAINED

Follow the code.

complete-ml-workflow.py
from sklearn.datasets import load_iris
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.25, stratify=y, random_state=7
)
baseline = DummyClassifier(strategy="most_frequent").fit(X_train, y_train)
model = make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000))
model.fit(X_train, y_train)
print("baseline:", accuracy_score(y_test, baseline.predict(X_test)))
print("model:", accuracy_score(y_test, model.predict(X_test)))

The built-in Iris data supplies feature rows and species labels. A stratified split preserves approximate class proportions in training and test sets. The baseline learns only the most common training class. The second pipeline learns training-set scaling and logistic-regression parameters together. Both are evaluated with the same test rows and accuracy metric so the comparison has a common frame. The exact scores are outputs of this particular small dataset and split, not promises about unrelated tasks.

This compact script omits several steps needed for a serious decision: a separate validation process for model choices, data provenance review, subgroup analysis, calibrated uncertainty, and monitoring after deployment. It is a map of the flow, not a claim that a few lines make a reliable production system. The cookbook shows fuller patterns while the chapters explain why each step exists.

04 / THE BOUNDARY

What the result does not say.

Machine learning is a broad field; this course establishes the concepts and common Python workflow rather than literally every method ever proposed. The same questions—what is the task, what data exists, what was learned, and how do we know it generalises—transfer to new libraries and algorithms.

The strongest habit is to state assumptions before presenting a result. A prediction is conditional on a representation, a training population, a fitted procedure, and an evaluation setting. When those conditions are visible, others can understand where the model is useful and where it should not be trusted.

05 / KEEP THIS

One clear idea.

A reliable ML result is a chain of justified decisions from task definition through monitoring.

THE CODE IN CONTEXT

The ML cookbook

Complete, explained Python workflows sit alongside this reading course.

Browse the cookbook
Finished reading?
Built with curiosity. By Navan Sami. ↗Machine learning with Python · From examples to trustworthy models.