Concepts / Model Evaluation Basics

Model Evaluation Basics

Building the model, however, is only part of the work.

  • Programming

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.

Input value 3Step 1: add one3 becomes 4Step 2: double4 becomes 8Pipeline output 8passes topasses result toreturns
What the value 3 looks like after each step when the steps run in the order add one, then double

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
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.

Worked example

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?

  1. 1
    Start

    The input value is 3, and this is what the first step receives.

  2. 2
    Step 1: double

    Doubling 3 gives 6. The output 6 is what the next step receives.

  3. 3
    Step 2: add one

    Adding one to 6 gives 7. This is the final output of the pipeline.

  4. 4
    Compare

    The original order returned 8. The reversed order returns 7. The same steps, in a different order, gave a different final result.

Result

7. The order of the steps changed the final result, even though neither step changed.

Key point

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

Definition

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.

Build and tune modelOffline, by the teamOffline evaluationScored on a pre-collectedtest setOnline testingRun inside the live systemLive usersBehavior observed in usethenusually followed byinvolves
The order in which a model moves from building and offline scoring to live online testing, and where each stage happens
AspectOffline evaluationOnline testing
Data usedA test set collected beforehandLive use of the algorithm inside the system
Question answeredHow well do the predictions match the test setWhat are the consequences of the algorithm for the whole system
Where it happensBefore the model meets usersInside the live website or service
Typical positionThe first check for user-facing systemsUsually 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 like

    Running add one then double on 3 returns 8, but running double then add one returns 7.

    Why it fails

    Each step receives the output of the step before it, so a different order changes the input each step sees.

    Do this instead

    Choose 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 fails

    Offline 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 instead

    After 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 fails

    A/B testing is a blind user study. Users do not know which group they belong to.

    Do this instead

    Remember 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 fails

    Bandit algorithms are a more elaborate family of online testing methods that go beyond A/B testing.

    Do this instead

    Treat 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

EASY

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.

Related concepts

More concepts starting with M