g↗genai/ learner
Data and Evaluation / Lesson 06

Loss: measuring prediction errors

As a model learns from examples, it can try to reduce a score called loss. Yet a lower loss score does not automatically mean a more useful model in the real world.

Concept + interactive labBeginner friendly

From a guess to an error score.

In supervised learning—learning from examples paired with known answers—training is the stage when a model adjusts learned settings. For each example, it predicts an output and compares it with the known value, called the target. A score can summarize how far its predictions miss.

In this lesson, you will follow five ideas in order: one prediction error, one combined score, how averaging and squaring errors differ, sliding a line to change the score, and why a low score alone does not show real-world usefulness.

Prediction error

The signed gap for one example: actual − predicted. A positive gap means the actual value is larger than the prediction.

Loss function

A rule that scores each prediction error and combines the scores, often by averaging, into one number called loss.

Think of a commute estimate: if you predict 25 minutes and the trip takes 35, the error is +10 minutes. A weekly loss score summarizes the five daily misses, much like one average for several quiz marks.

Running example: Rohan’s Neighborhood Courier

Rohan (an invented local courier for this lesson) predicts delivery time in minutes from distance in kilometers using a simple line: 10 minutes pickup base + 4 minutes per km. The slope is the added minutes for each extra kilometer. Here are five invented recent trips: 1 km → 14 min, 2 km → 18 min, 3 km → 22 min, 4 km → 26 min, and 5 km → 52 min after a bridge closure. That last time sits far from the others; such an unusually distant value is called an outlier.

With a slope of 4 minutes per km, Rohan’s line predicts 14, 18, 22, 26, and 30 minutes. The first four trips have zero error, while the 5 km bridge-delay trip is off by +22 minutes. Averaging the five error sizes without their signs gives a score of 4.4 minutes. This is the mean absolute error, or MAE.

From errors to loss: Actual values 14, 18, 22, 26, and 52 pair with Predicted values 14, 18, 22, 26, and 30; their gaps flow into the Loss rule and One score of 4.4 min for Five trips. The Analogy card shows different-sized parcels, and Key takeaways lists three points.
Three pairs illustrate the pattern; the 4.4-minute MAE uses all five invented courier trips.

Different loss functions punish mistakes differently.

Not every loss function treats a big miss the same way. Two common loss functions for numeric predictions are MAE (Mean Absolute Error) and MSE (Mean Squared Error).

MAE (Mean Absolute Error)

Drops the minus sign on each error and takes the average. Every extra minute of error adds the same penalty, whether the miss is 2 minutes or 22 minutes.

MSE (Mean Squared Error)

Squares each error before averaging. A 2-minute miss becomes 4, while a 22-minute miss becomes 484—over a hundred times larger.

Because MSE squares large misses, it pulls Rohan’s line upward toward the 52-minute bridge-delay trip. On this dataset, MAE picks 4.0 min/km (MAE = 4.4 min, MSE = 96.8), fitting the four typical trips cleanly. MSE picks 6.0 min/km (MSE = 52.8, MAE = 6.4 min), shrinking the one huge squared error at the cost of overestimating every typical trip by 2 to 8 minutes.

For an everyday comparison, imagine two weather apps: one is off by 1°C every day, while another is exact four days a week and off by 15°C on Friday. Which feels worse depends on whether one huge surprise hurts you more than steady small misses.

A scoring rule also affects what the model is encouraged to improve: the choice of loss defines how different prediction misses count.

Two ways to score error: MAE keeps misses of 2, 4, and 22 minutes as 2, 4, and 22; MSE squares them to 4, 16, and 484. The Analogy card compares a heavy parcel, and Key takeaways lists three points.
On the exact same five trips, MAE and MSE disagree on which line is best because MSE weights the single outlier much more heavily.

Slide a line and watch the loss change.

Try adjusting Rohan’s prediction line below. Like a ruler laid across five pins on a board, moving the slope changes every trip’s vertical error bar at once—and MAE and MSE score that trade-off differently.

  1. Start on MAE at 4.0 min/km. Notice that four trips have 0 error while the 5 km bridge-delay trip has a +22 min error (MAE = 4.4 min, MSE = 96.8).
  2. Switch the highlight to MSE, then slide up to 6.0 min/km (or click Best MSE (6.0)). Watch MSE drop from 96.8 to 52.8 while MAE climbs from 4.4 to 6.4 min.
  3. Compare the table rows at 6.0 min/km: lowering MSE made all four typical trips less accurate just to shrink the single squared outlier error.
  4. Click Reset line to return to the starting setup.
Rohan’s courier line & loss explorer
1. Choose which loss function to highlight
4.0 min/km
Or jump to a preset line
0m15m30m45m60m1 km2 km3 km4 km5 kmTrip 1 (1 km): actual 14 min, predicted 14 minTrip 2 (2 km): actual 18 min, predicted 18 minTrip 3 (3 km): actual 22 min, predicted 22 minTrip 4 (4 km): actual 26 min, predicted 26 minTrip 5 (5 km): actual 52 min, predicted 30 min
MAE (mean absolute error) · Active
4.4 min

Lowest possible: 4.4 min at 4.0

MSE (mean squared error)
96.8 min²

Lowest possible: 52.8 at 6.0

At 4.0 min/km, MAE hits its lowest value (4.4 min) because 4 of 5 trips have zero error. MSE stays high (96.8) because the single +22 min delay squares to 484.
TripActualPredictedErrorAbs error
1 km (Typical)14 min14 min0 min0 min
2 km (Typical)18 min18 min0 min0 min
3 km (Typical)22 min22 min0 min0 min
4 km (Typical)26 min26 min0 min0 min
5 km (Bridge delay)52 min30 min+22 min22 min

Illustrative toy dataset: five invented trips with a fixed 10-minute pickup base, designed to show how MAE and MSE react differently to a single large outlier.

Why low loss does not guarantee a useful model.

It is tempting to assume that whichever model has the lowest loss is automatically the most useful. A low loss score means predictions fit a chosen scoring rule on a chosen set of recorded targets. It does not by itself tell us whether people get a useful result.

Different costs for different mistakes

MAE and MSE treat being 10 minutes early the same as being 10 minutes late. In this invented courier scenario, arriving late leaves a customer waiting, while arriving early may be less costly.

A measured target can be a proxy

A proxy target is a measurable stand-in for the real goal. Minimizing prediction error on watch-time, for example, could still recommend content that frustrates viewers.

Past data vs. new conditions

A model can score well on familiar routes yet do poorly on new routes, seasons, or groups not well represented in its examples.

Consider a fictional hospital scheduling operating rooms: predicting that a surgery will finish 20 minutes sooner than it actually does can delay every patient after it, whereas leaving a 20-minute buffer causes far less disruption. Equal numeric error does not mean equal real-world harm.

A low score is not the whole story: a Loss score summarizes past trips under a chosen error rule, while Real-world outcome shows different costs for Early and Late arrival. The Analogy card compares practice and a real match, and Key takeaways lists three points.
A loss score can guide training, while usefulness depends on the goal, the cost of mistakes, and performance on new cases.

Limits and quick questions.

Keep three practical limits in mind whenever you read a loss score:

  • Averages hide individual failures: One low average loss can still mask terrible predictions on a small but critical group of cases.
  • The known values may be off: If recorded targets are noisy or biased, minimizing loss can reproduce those flaws.
  • A training score is not a real-world check: A training loss is the score on examples used while a model learns. Teams also check separate examples and the effects of mistakes before relying on a model.
  • Is zero loss always the goal?

    No. Outcomes can include unpredictable events like a bridge closure. A zero training loss can reflect details of those examples that do not hold on new trips. This is called overfitting; the next lesson explores it further.

  • Can you compare an MAE of 4.4 directly to an MSE of 52.8?

    No. MAE is measured in the original units (minutes), while MSE is measured in squared units (minutes²). Compare candidate models using the same loss function on the same dataset.

  • If low loss does not prove usefulness, why train with it at all?

    Training algorithms need a fast, computable score to adjust model settings step by step. Loss serves as the training compass, while real-world evaluation checks whether the destination is actually helpful.

✎ Try it yourselfKnowledge check · Practice only

Check your understanding.

A courier team compares two delivery-time models on the same recorded trips. Model A has a lower mean absolute error (MAE = 4 min), but it often predicts an arrival 4 minutes before the courier actually arrives, leaving customers waiting. Model B has a slightly higher MAE (5 min) because it includes a small buffer and customers seldom wait. What does this show?

Take this with you.

Loss is a training compass, not the final verdict. A loss function turns prediction errors from examples into one score—and choices like MAE vs. MSE decide how heavily outliers pull the model. Check real-world costs, whether the scored target matches the goal, and new examples before calling a low-loss model useful.

Ready to continue? Return to Data and Evaluation.