Model Evaluation Basics
Building the model, however, is only part of the work.
Why Training Is Not the Finish Line
Imagine you have built a model that predicts which items a user will want to see next on a shopping website. You have trained it, you have checked it, and it looks promising. Building the model, however, is only part of the work. Once a model exists, you need a way to judge how well it works, and you may also need a way to adjust the settings that shaped it.
This topic introduces two linked ideas. Advanced model evaluation is about judging how well a model performs. Parameter tuning is about adjusting the settings that shape the model. Evaluation and tuning work together: tuning produces different versions of a model, and evaluation is how you compare those versions. Read together, the two form a loop of adjust, judge, and adjust again.
The article then adds a third idea that ties the workflow together: pipelines, which chain steps so that a workflow runs in order and is wrapped into a single unit. We will start with pipelines, because the order of steps is something you can trace by hand before you ever touch a real model.
Chaining Steps Into a Pipeline
A pipeline chains steps so that each step receives the output of the previous one. The whole chain is encapsulated as one unit, so the workflow can be run as a single operation rather than as a set of separate manual actions. The steps are ordered, and the order matters, because each step works on whatever the previous step produced.
It is important to see what a pipeline does not do. It does not change what each step does. A step still does its own job. The pipeline only arranges the steps and runs them in sequence, passing each result forward to the next step as its input.
What do you think happens?
A pipeline first adds one to a value and then doubles it. If you start with 3, what does the pipeline return? Work it out on paper before reading on.
Reveal answer
8
Adding one to 3 gives 4. Doubling 4 gives 8. Each step receives the output of the step before it, so the second step works on 4, not on the original 3.
Why Step Order Changes the Result
Now take the same two steps and run them in the opposite order: doubling first, then adding one. The steps themselves are unchanged. Only their arrangement is different. Trace the value again, one step at a time, and compare the final answer.
Same two steps, reversed order
A pipeline contains two steps: add one, and double. The input value is 3. Run the steps in the order double first, then add one. What does the pipeline return?
- 1Start
The input value is 3, and this is what the first step receives.
- 2Step 1: double
Doubling 3 gives 6. The output 6 is what the next step receives.
- 3Step 2: add one
Adding one to 6 gives 7. This is the final output of the pipeline.
- 4Compare
The original order returned 8. The reversed order returns 7. The same steps, in a different order, gave a different final result.
7. The order of the steps changed the final result, even though neither step changed.
The order of steps in a chain affects the final result, so the order must be chosen deliberately. Before you build a pipeline, decide what each step needs from the step before it, and arrange the steps to match.
Judging a Model With Offline Evaluation
Offline evaluation assesses an algorithm's predictions on a test set collected beforehand. It is the first step for user-facing systems.
The key idea is that the model's predictions are checked against a test set that already exists before the model meets real users. Offline evaluation therefore asks a narrow question: how well do the model's predictions match the data it is being scored against? Going back to the shopping example, the team can check whether the items the model predicts a user will want actually match what the test set says those users wanted.
The test set is collected beforehand, which means it is fixed and known before the model is scored on it. Because the score is taken from this fixed set, different versions of a model can be compared on the same footing. This is what makes evaluation useful for the tuning loop: you tune, score each version on the same test set, and keep the version that scores better.
From Offline Check to Live Users
Once an algorithm is part of a live website, the question changes. It is no longer enough to ask whether the predictions match a test set. The team must ask what happens to the whole system when users meet the new behavior. This is called online testing, also known as live testing. It evaluates the consequences of employing the algorithm in the overall system.
Online testing usually comes next, after offline evaluation. The reason is that user behavior can change in unexpected ways. A model can score well on a test set and still shift how people use the website once they see its recommendations. Offline evaluation cannot show those shifts, so for user-facing systems the live check is not something to skip.
| Aspect | Offline evaluation | Online testing |
|---|---|---|
| Data used | A test set collected beforehand | Live use of the algorithm inside the system |
| Question answered | How well do the predictions match the test set | What are the consequences of the algorithm for the whole system |
| Where it happens | Before the model meets users | Inside the live website or service |
| Typical position | The first check for user-facing systems | Usually the next step after offline evaluation |
Offline evaluation and online testing answer different questions
Online Testing Methods
Online testing has several methods. The most common protection against unexpected behavior is A/B testing. Another family, bandit algorithms, goes further. Both evaluate an algorithm's consequences with live use, and the two are described below.
Mistakes to Avoid When Evaluating Models
Common mistake Assuming the order of steps in a pipeline does not matter
What it looks likeRunning add one then double on 3 returns 8, but running double then add one returns 7.
Why it failsEach step receives the output of the step before it, so a different order changes the input each step sees.
Do this insteadChoose the order of steps deliberately, based on what each step needs from the previous one.
Common mistake Treating a strong offline score as proof of how live users will behave
Why it failsOffline evaluation scores predictions against a test set collected beforehand. It does not show what happens when user behavior changes in the live system.
Do this insteadAfter offline evaluation, run online testing to see the consequences of the algorithm in the whole system.
Common mistake Thinking users in an A/B test know which algorithm they are seeing
Why it failsA/B testing is a blind user study. Users do not know which group they belong to.
Do this insteadRemember that the comparison depends on users experiencing their assigned algorithm without knowing it is a test.
Common mistake Confusing bandit algorithms with a simple fixed split
Why it failsBandit algorithms are a more elaborate family of online testing methods that go beyond A/B testing.
Do this insteadTreat A/B testing as one method within online testing, and bandit algorithms as a more involved family beyond it.
Tracing a Two-Step Chain Yourself
A pipeline has two steps: first double the value, then add three. The input value is 5. Trace the value through each step and find the final output. Then run the same two steps in the reverse order, starting again from 5. Does the final result change? Explain why in one or two sentences.
Hints
- Write down the value after each step, the same way the worked example did.
- For the first order, doubling 5 comes before adding three.
- For the reverse order, adding three to 5 comes first, and doubling comes second.
- Compare the two final numbers, then ask which step received a different input in each order.
Key Takeaways
- Model evaluation judges how well a model performs, and parameter tuning adjusts the settings that shape it; together they form a loop of adjust, judge, and adjust again.
- A pipeline chains steps so each step receives the output of the previous one, and it encapsulates the workflow as one unit; the order of the steps changes the final result.
- Offline evaluation scores a model's predictions on a test set collected beforehand and is the first step for user-facing systems.
- Online testing evaluates the consequences of an algorithm inside the whole system and usually follows offline evaluation, because user behavior can change in unexpected ways.
- A/B testing splits users between two algorithms without their knowledge and compares success metrics, while bandit algorithms are a more elaborate family of online testing methods beyond A/B testing.