The machine learning workflow

Data, pipeline, train, compare, deploy, monitor: the loop every project follows.

Lesson 3 of 6610 minBeginner

You will learn to

  • Describe each stage of the workflow
  • Explain why the loop never really ends
  • Map each stage to a screen in mlflow

Before this lesson

Intuition

A machine learning project is closer to running a garden than to building a bridge. A bridge is designed, built and finished. A garden is planted, watched, adjusted after each season and never really done. A model is the same: it is built from past data, and the moment it is used, the world starts to drift away from the data it learned from.

The work follows six steps, and the last one points back to the first:

  1. Data. Collect and load the examples, and check their quality.
  2. Pipeline. Describe how raw columns become model inputs (cleaning, encoding, scaling) and which algorithms to try.
  3. Train. Fit the candidate models and measure each one on data it did not train on.
  4. Compare. Read the results, including a trivial baseline, and choose a model, or decide to go back and improve.
  5. Deploy. Make the chosen model available to answer new cases.
  6. Monitor. Watch what goes in and what comes out, and notice when the model stops being reliable.

Most of the time is spent going backwards. Training shows that a column is full of gaps, so you return to data. A comparison shows that the model is not better than a baseline, so you rethink the pipeline or even the problem framing. This is normal: the loop is the method, not a sign that something went wrong.

Picture it

1Data2Pipeline3Train4Compare5Deploy6MonitorNew data and drift send you back
The six steps of the workflow. The dashed arrow is the part people forget: what you learn while monitoring sends you back to data, pipeline or training.

Where does the effort go? In practice, the first two steps usually take the largest share of the time, and the choice of algorithm the smallest. Better data and better framing tend to help more than a cleverer algorithm.

The math

A workflow has little formula, but it has one important rule about numbers: each stage must be judged on data the earlier stages did not use. Three roles for data keep estimates honest:

  • Training data is used to fit the models.
  • Validation data (folds, in cross-validation) is used to compare models and settings. After many comparisons it is slightly optimistic.
  • Test data is touched once, at the end, to report the result.

The loop needs one more number, a trigger for going back. If the score you measured when the model went live is s0s_0, and sts_t is the same score measured later, then retraining is worth considering when:

s0−st>δs_0 - s_t > \delta

where δ\delta is the drop you agreed to tolerate. Choosing δ\delta is a business decision (it depends on what a worse model costs), not a statistical one, which is why it belongs in the framing step.

Worked example

A model goes live with a quality score of s0=0.82s_0 = 0.82. The team agrees to tolerate a drop of δ=0.05\delta = 0.05, so the alarm level is 0.82−0.05=0.770.82 - 0.05 = 0.77. (The weekly scores below are illustrative.)

Week12345
Score0.820.810.820.790.76
Drop from 0.820.000.010.000.030.06

Weeks 1 to 4 are within tolerance: small moves up and down are noise, and 0.79 is a drop of 0.03, less than 0.05. In week 5 the drop is 0.06, above the tolerance. That sends the team back around the loop: look at the new data (is something different about the customers?), update the pipeline if needed, train again, compare the new candidate with the model in production, and deploy only if it is clearly better.

Notice that no step could have been skipped to save the project. A model that is never monitored would still be producing answers in week 5, silently worse.

How mlflow does it

Every page of a project shows a flow bar with the same six steps: Data, Pipeline, Train, Results, Deploy and Monitor. Each step is a link that opens the right screen, done steps are marked and the current one is highlighted. The project Overview also names the next step and has a primary button whose label changes with the state of the project, for example Add data, New pipeline, Train a pipeline, Deploy best model or Open deployment.

Each stage has a home in the navigation:

StageWhere in mlflow
DataData: upload a file or connect a database, then explore the data profile
PipelinePipelines: build preprocessing steps and pick algorithms
TrainPipelines: train from the pipeline; progress shows in a training overlay
CompareRuns: open a run and read its Leaderboard
DeployModels to register a version, Deployments to serve it
MonitorDeployments: the deployment's Monitor tab, plus alert rules

The pipeline versions, run history and model versions are all kept, so going around the loop again never overwrites what you had before.

Common mistakes

  • Treating deployment as the finish line. Without monitoring, a model degrades unnoticed. Plan the Monitor step and a tolerance before you deploy.
  • Skipping the baseline. If you never compare against a trivial reference, you cannot tell whether the whole workflow added value. See Baselines: start simple.
  • Jumping to algorithms. Spending days on model choice while the data has gaps, leaks or the wrong target is the most common waste. Look at the data and the framing first.
  • Judging the model on the data it was trained on. Scores must come from data the model did not see, otherwise every stage looks better than reality.
  • Reading a bad result as a failure of the loop. A poor comparison is information. Go back one step, change one thing, and run again so that you know which change helped.
  • Changing many things at once. If you alter the data, the pipeline and the algorithm together, you will not know what moved the score. Change one thing per pass.

Try it in mlflow

Open your project Overview

  1. Open a project and go to Overview.
  2. Read the flow bar under the top bar: it lists the six steps and marks the ones already done, and the current one is highlighted.
  3. Follow the Next step button and see which screen it opens.
Open in mlflow

Read in the docs

Check your understanding

  1. 1. Which order describes the steps shown in the mlflow project workflow?
  2. 2. Why is the workflow described as a loop and not a straight line?
  3. 3. Where in mlflow do you compare the models a training run produced?