Concepts / Offline Evaluation

Offline Evaluation

Offline evaluation checks algorithmic predictions against a test set collected beforehand, and it is only the first step for a user-facing machine learning system.

  • Programming

Why a Good Test Score Is Not Enough

Building a machine learning model is only half the job. Before anyone relies on its predictions, you need evidence that those predictions are good. The first and most common source of that evidence is offline evaluation: checking algorithmic predictions against a test set that was collected beforehand. The model never has to face live users during this stage. You hold back some data, let the model predict on it, and compare those predictions with the answers you already know.

What do you think happens?

A model scores well on a held-out test set. Will the same predictions produce the same user behavior once they are shown inside a live product?

  • Yes, a good test score guarantees the same behavior

  • Not necessarily, because live behavior can differ from test-set behavior

Reveal answer
Answer:

Not necessarily. Predictions that look good on a test set can still behave differently once they are placed inside a real product.

A test set does not respond to the system. In a user-facing product, predictions change what users see, and users then respond to what they see. Those responses can ripple through the system in ways no one predicted.

This article follows that question step by step. First you will trace how offline evaluation scores predictions item by item. Then you will see why a strong offline score is only the first step for a user-facing system, and how online testing, including A/B testing, examines what happens once real people interact with the algorithm.

Tracing One Test Set, Item by Item

Offline evaluation starts with a test set. You collect a set of examples ahead of time, and for each one you already know what actually happened. These known answers are the true labels. You then let the algorithm make a prediction for each of the same items. Scoring means lining up each prediction with its matching true label and counting how often the two agree.

Because the test set was gathered before the evaluation begins, the scoring is repeatable. You can rerun the same comparison on the same data and check whether a change to the model really helped. This repeatability is the main strength of offline evaluation, and it is a large part of why the method is so widely used early in development.

Item 1truth 1 | predicted 1 |matchItem 2truth 0 | predicted 0 |matchItem 3truth 1 | predicted 0 |mismatchItem 4truth 1 | predicted 1 |matchItem 5truth 0 | predicted 0 |matchItem 6truth 0 | predicted 1 |mismatchItem 7truth 1 | predicted 1 |matchItem 8truth 0 | predicted 0 |match
How does each prediction line up with its matching true label in the held-out test set? Items 3 and 6 are the two places where the prediction and the truth disagree.

The example below makes this concrete. It uses invented labels and invented predictions for eight test items. The true labels are the answers collected beforehand, and the predictions are what the model produced for the same items. The score here is simply the number of matches divided by the number of items.

python
Output (expected)
Correct: 6 out of 8
Score: 0.75
Walk through it
  1. 1
    Line 1 stores the eight true labels in a list.
  2. 2
    Line 2 stores the eight predictions in the same order, so position 3 in both lists refers to the same test item.
  3. 3
    Lines 4 to 7 walk through the pairs and add one to correct each time the prediction matches the truth.
  4. 4
    The score divides the number of matches by the number of items, which gives 6 divided by 8, or 0.75.
Notes on the code
  • true_labels holds the answers collected beforehand
  • predictions holds what the model produced for the same items, in the same order
  • zip pairs the item at position 0 with position 0, position 1 with position 1, and so on
  • correct counts the pairs where the prediction equals the truth

Trace the output by hand against the diagram. Items 1, 2, 4, 5, 7, and 8 match. Items 3 and 6 do not, because item 3 was predicted 0 when the truth was 1, and item 6 was predicted 1 when the truth was 0. Six matches out of eight items gives the score of 0.75 printed at the end.

What Offline Evaluation Leaves Out

A good offline score tells you that the model predicts well on the data you held back. It does not tell you what happens when the model's output is shown to people. In a user-facing system, the predictions become part of the product. They change what users see, and users then respond to what they see.

The source makes a specific point here. Changing the recommendations or search results a website shows its users can drastically change how those users behave. A recommendation list that performs well in an offline test may shift what people click, what they buy, or how long they stay, and those shifts can ripple through the rest of the system in ways no one predicted. Offline evaluation cannot reveal these effects, because the test set does not respond to the system.

Build a modelthe model is only half thejobOffline evaluationscored on a test setcollected beforehandOnline testinglive users interact withthe algorithmDecide based onresultschoice made from recordedmetricsfirst checknext step for user-facing systemsconsequences observed
What comes first, what comes after, and how does a model move from test-set scoring to live user traffic? Offline evaluation comes first, and online testing follows for user-facing systems.

The two stages answer different questions. Offline evaluation asks how well an algorithm's predictions match a test set collected beforehand. Online testing, also called live testing, asks what happens when that algorithm is actually part of the product and real users interact with it. Online testing evaluates the consequences of employing an algorithm in the overall system, not just the accuracy of its predictions.

Following a User Through an A/B Split

Most user-facing services use A/B testing to observe the consequences of an algorithm. A/B testing is a form of blind user study. Without their knowledge, a selected portion of users is given a website or service that uses algorithm A, while the rest of the users are given the same kind of service using algorithm B. Because users do not know which version they see, their behavior reflects ordinary use rather than how they act when they know they are being tested.

Incoming usersDivide users into twogroupsGroup A: algorithm ASuccess metrics for ACompare metricsChoose between A andBGroup B: algorithm BSuccess metrics for Ba selected portionthe restrecorded over a set periodrecorded over a set period
Which users see which algorithm, and how do the two groups' metrics get compared side by side? Each user lands in exactly one group, and the groups stay separate so their metrics can be compared.

Trace one user through this flow. The user arrives and is placed into one group without noticing. If that user lands in the algorithm A group, every success metric recorded for that person counts toward group A. The same user never contributes to group B, which is why the two groups must be kept separate. Both groups are observed for the same set period, and when that period ends the metrics for A and B are compared.

The source notes that often A is a new model while B is the established system. The test therefore asks whether the new model earns its place in front of real users. A choice between the two approaches is made according to the recorded metrics.

python
Notes on the code
  • The sketch shows the routing idea in miniature only
  • A real A/B test also records success metrics over a set period and compares them

Bandit Algorithms as a Further Option

A/B testing is not the only way to run online tests. The source mentions more elaborate mechanisms for online testing that go beyond A/B testing, and it names bandit algorithms as one example. At this stage the important point is that bandit algorithms belong to the online testing family. Like A/B testing, they evaluate algorithms through live user interaction, but they go beyond a simple fixed split between two groups.

The mechanics of how bandit algorithms choose between options are a topic for further study. For now, it is enough to know that these approaches exist and that they, too, are a form of online testing rather than offline evaluation.

Mistakes Beginners Make With Offline Scores

  • Common mistake

    Treating a high offline score as proof that users will benefit

    What it looks like

    A recommendation list scores well on the held-out test set, so the team ships it to everyone.

    Why it fails

    A test set does not respond to the system. Changing what users see can shift what they click, buy, or how long they stay, and those effects are not visible offline.

    Do this instead

    Treat the offline score as the first step, then run online testing such as A/B testing to observe real user behavior.

  • Common mistake

    Scoring predictions against data that was not held back

    What it looks like

    The model is scored on the same examples it was trained on.

    Why it fails

    The test set is meant to be collected beforehand and kept apart from what the model is judged on, so the score reflects predictions on data the evaluation has not already used.

    Do this instead

    Hold back a separate set of examples, collected ahead of time, and score predictions only against that set.

  • Common mistake

    Mixing up the two groups in an A/B test

    What it looks like

    A user who was shown algorithm A is counted in the metrics for algorithm B.

    Why it fails

    The comparison only means something when each user lands in exactly one group and the groups remain separate.

    Do this instead

    Assign each user to one group and record metrics for that group only.

  • Common mistake

    Forgetting that the metrics must be recorded over a set period before comparing the two groups

Try It: Change One Prediction

EASY

Using the same true_labels and predictions lists from the scoring example, change the prediction for item 3 from 0 to 1. Recompute the number of correct predictions and the score. What is the new score?

Hints
  • Item 3 is the third position in the list, so its index is 2. Its true label is 1.
  • Count the matches again after the change before dividing by the total of 8 items. Item 6 still does not match.

Summary of the Offline-to-Online Path

  1. 1
    Offline evaluation checks algorithmic predictions against a test set collected beforehand, without exposing anything to real users.
  2. 2
    Because the test set was gathered before the evaluation begins, the scoring is repeatable, which is its main strength.
  3. 3
    For a user-facing system, offline evaluation is only the first step, because changing what users see can produce unexpected consequences.
  4. 4
    A/B testing is a blind user study that splits users between algorithm A and algorithm B, records success metrics for both groups, and selects between them.
  5. 5
    Bandit algorithms are more elaborate online testing mechanisms that go beyond A/B testing.

At a glance

  • Offline evaluation scores predictions against a test set collected beforehand, letting you check an algorithm without exposing anything to real users.
  • A good offline score shows the model predicts well on held-back data, but it does not show what happens when users respond to the predictions in a live product.
  • Online testing evaluates the consequences of an algorithm inside the overall system, and A/B testing does this by splitting users into two groups and comparing success metrics.
  • Bandit algorithms are a more elaborate form of online testing that go beyond a simple A/B split.

Related concepts

More concepts starting with O