Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 111 ยท Getting Started

The Machine Learning Workflow

Walk through the full machine learning workflow: framing the problem, data, split, baseline, training, evaluation, iteration and deployment, with a first model.

Building a useful model is much more than calling fit. Teams that succeed follow a repeatable loop: define the problem, get the data, set aside data for honest testing, build a trivial baseline, train a real model, measure it, and improve it step by step. Skipping a step is the usual reason a model looks great in a notebook and fails in the real world.

This lesson gives you the map. Later lessons zoom into each stop, so here we focus on how the pieces fit, and we finish with a small end-to-end example you can run.

The loop at a glance

flowchart LR
    A["Frame the problem"] --> B["Collect and clean data"]
    B --> C["Split: train and test"]
    C --> D["Baseline"]
    D --> E["Train a model"]
    E --> F["Evaluate"]
    F -->|"not good enough"| E
    F -->|"good enough"| G["Deploy and monitor"]
    G -->|"data drifts"| B

The workflow is a loop: evaluation sends you back to modeling, and monitoring can send you back to the data.

Step 1: Frame the problem

Start with a question a model could answer and a decision that the answer would change. Be concrete about four things.

  • The target. What exactly are you predicting, and for which unit (customer, order, day)?
  • The type. A number is regression, a category is classification, and groups without labels are clustering.
  • The metric. How will you judge success? "Catch most fraud without blocking many good customers" points to precision and recall, not plain accuracy. See classification metrics.
  • The prediction moment. What information will you actually have at the time you must predict? Using facts that only become known later is a bug called leakage, covered in train, validation and test sets.

Step 2: Get and inspect the data

Real projects spend most of their time here. You gather the data, check its shape, look for missing values, impossible values and duplicates, and plot a few distributions. A quick look often changes the plan. Tools from pandas make this fast, and working with datasets shows the scikit-learn side.

Step 3: Split before you peek

Divide the data into a training set the model learns from and a test set it never touches until the very end. If you judge a model on the data it trained on, you only measure how well it memorized. The test set simulates the future.

Step 4: Build a baseline

A baseline is the simplest reasonable predictor: always guess the most common class, or always guess the average price. Every real model must beat it, otherwise the model adds complexity without value. Baselines and dummy models goes into detail.

Step 5: Train, evaluate, iterate

Now you try real models. You fit on the training data, score on held-out data, look at the mistakes, and adjust: new features, a different algorithm, different settings. Each round should teach you something. Resist the urge to tune against the test set; if you do, it stops being an honest judge. Later lessons on cross-validation and hyperparameter tuning show the safe way.

Step 6: Deploy and monitor

A model that lives in a notebook helps no one. Deployment means making predictions available to an application, and monitoring means watching that they stay good, because the world drifts. We cover this in saving models and deploying. For now, remember that the work is not finished when the score looks good.

A model is only one step

Frame Target, metric, decision.
Data Collect, inspect, clean.
Split Hide a test set first.
Baseline The bar to beat.
1 / 2

A first end-to-end run

Let us follow the loop on a small, built-in dataset. The iris data has 150 flowers, four measurements each, and three species. The task is classification: predict the species from the measurements.

Python Frame, split, baseline, train, evaluate

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The baseline lands near one third, since the three classes are balanced. The logistic regression is far above it, so the model clearly learned something. Reading the result against the baseline, and not as a lonely number, is the habit to build.

Looking at the mistakes

A single score hides where the model fails. Always check at least a handful of wrong predictions.

Python Which flowers did the model get wrong?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

This particular split happens to produce no test mistakes, so the loop prints nothing. On another split, or a harder dataset, the errors you would see are typically between the two species whose measurements overlap. That is useful knowledge: it tells you where more data or better features would help. Note also that the test score here is higher than the training score; with only 45 test flowers, one lucky split can do that, which is why a single small test set is a noisy judge. A large gap the other way, with training far above test, would signal overfitting, a topic for overfitting and underfitting.

The test set was used exactly once here, for the final report. If you keep adjusting the model after every look at the test score, you quietly fit the test set too. The remedy is a separate validation set or cross-validation, both coming soon.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why do we split the data before training?

    A held-out test set simulates future data. Scoring on training data only measures memorization.
  2. 2. What is the purpose of a baseline model?

    A baseline sets the bar. If a complex model does not clearly beat the trivial one, it is not adding value.
  3. 3. Which is a sign that you are leaking information from the future into your features?

    Features must be available at prediction time. Using facts recorded later makes the evaluation unrealistically good.
  4. 4. After deployment, what should you do?

    Real-world data changes, so a model's quality can decay. Monitoring catches that early.

Summary

  • The workflow is a loop: frame the problem, get data, split, baseline, train, evaluate, iterate, deploy and monitor.
  • Decide the target, task type, metric and prediction moment before modeling.
  • Always split before looking closely at the data's labels, and keep the test set for the final check.
  • A baseline gives context to every score; inspect the mistakes, not just the number.
  • Shipping a model is the start of monitoring, not the end of the project.

Next: The scikit-learn API