Skip to content
Kuza Ndoto Academy

The Machine Learning Workflow

IntermediateChapter 1 · Page 4 of 264 min readUpdated 15 Nov 2026

Training a model is only one step in a machine learning project. Real projects follow a workflow that starts with a clear question and ends with a model that is deployed, monitored and improved. Following the steps in order prevents the most common and most expensive mistakes.

The steps at a glance

  1. Define the problem. What exactly will you predict, for whom, and how will success be measured?
  2. Collect data. Gather examples that represent the real situation.
  3. Explore the data. Look at distributions, missing values and relationships.
  4. Prepare the data. Clean, encode and scale features.
  5. Split the data. Keep a test set aside that the model never sees during training.
  6. Train models. Start with a simple baseline, then try stronger models.
  7. Evaluate and tune. Compare models with suitable metrics and cross-validation.
  8. Deploy. Put the model where people or systems can use it.
  9. Monitor and maintain. Watch for falling performance and retrain when needed.
Define Collect Prepare Split Train Evaluate Deploy Monitor not good enough? improve features or model drift detected: collect fresh data and retrain
Figure 1. The workflow is a loop, not a straight line: evaluation sends you back to preparation, and monitoring sends you back to data collection.

1. Define the problem

A vague goal such as "use AI on our sales data" leads nowhere. A good problem statement says what is predicted and why it matters: "Predict which SACCO members are likely to miss a loan repayment next month, so loan officers can call them early." This tells you the label (missed repayment: yes or no), the type of task (classification) and the cost of mistakes (missing a risky member is worse than an extra phone call).

Also ask whether ML is needed at all. If three simple rules solve the problem, use the rules.

2–4. Collect, explore and prepare

Most project time goes into data. You need enough rows, the right columns and labels you trust. Exploring with pandas and charts (see The Data Science Workflow) reveals problems early: impossible ages, duplicated rows, a label that is 98% "no". Preparation then turns raw data into model-ready features; see Cleaning Data for ML and Feature Scaling.

5–7. Split, train and evaluate in code

Here is a compact end-to-end example on the built-in iris flower dataset (150 flowers, 4 measurements each, 3 species). First, split the data:

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y
)
print(X_train.shape, X_test.shape)
(120, 4) (30, 4)

Next, build a pipeline that scales the features and then fits a classifier, train it on the training set only, and score it on the test set:

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score

model = make_pipeline(StandardScaler(), LogisticRegression())
model.fit(X_train, y_train)

accuracy = accuracy_score(y_test, model.predict(X_test))
print(f"Test accuracy: {accuracy:.2f}")

Iris is an easy dataset, so you should see a test accuracy of roughly 0.93 to 1.00. The exact value depends on which 30 flowers land in the test set.

Tip

Always compare against a baseline. A "model" that always predicts the most common class gets about 0.33 on iris. If your fancy model can't clearly beat the baseline, something is wrong. scikit-learn's DummyClassifier gives you this baseline in one line.

8–9. Deploy and monitor

Once you're happy with the model, save it so another program, such as a Django web app, can load it and make predictions:

import joblib

joblib.dump(model, "iris_model.joblib")       # save to a file

loaded = joblib.load("iris_model.joblib")     # later, in another program
print(loaded.predict([[5.1, 3.5, 1.4, 0.2]]))
[0]

Class 0 is setosa, whose short, narrow petals make it very easy to recognise. After deployment the world keeps changing: prices rise, customer behaviour shifts, new scam tactics appear. This is called data drift. Track the model's performance over time and retrain with fresh data when it slips.

Common mistake

Looking at the test set again and again while tuning. Every time you adjust the model because of a test score, information leaks from the test set into your choices, and the final score becomes too optimistic. Tune with cross-validation on the training data and touch the test set once, at the end.

Key points

  • Start with a precise problem statement and a success metric.
  • Data collection, exploration and preparation take most of the effort.
  • Split before training, compare with a baseline, and use pipelines to keep steps in order.
  • Deployment is not the end: monitor for drift and retrain.
Up next · New chapter: Data PreparationFeatures & LabelsWhat a model learns from and predicts.
→

Tip: use the ← and → keys to move between pages.