Go to Map Courses Lab Glossary How it works Troubleshooting Start →
ITEN
← Course 04 · Sensing motion (Lesson 04.04 · 16 minutes · Camera or sensors · First model)

Predicting a number.

How fast the rhythm is, how many steps, how much battery will be left tonight. Here a model answers with a number instead of a class, and you learn to measure how far off it is and where it shouldn't be trusted.

What you learn
  1. What changes in a model when the answer is a number
  2. How to measure the error of an estimate
  3. Why a model gets it wrong outside the values it has seen
  4. What a forecast over time is, and how to give the margin of an estimate
You need to know

If you don't remember one of these, the link takes you to the chapter that explains it.

How do you want to follow it
Preparing the scene…
  1. 01 A number

    When the answer is a number.

    How many steps you've taken, how many degrees the phone is tilted, how fast the rhythm is as you shake it. These are questions with a number as the answer. The model doesn't pick from a list, it estimates a value that could be anything. That's regression01.04. What changes is the last layer of the network, which gives a single number instead of a percentage for each class.

    In practice. If the answer has only a few possible values, like empty, half and full, a classification is easier to train. Regression is for when the values in between really matter.

01 / 07
(Go deeper)

A few more numbers.


(01)

MAE and RMSE

Next to the MAE you'll often see the RMSE, the square root of the average of the squared errors. You read it in the same unit, but it gives more weight to big errors. With four errors of 1, 1, 1 and 9, the MAE is 3 and the RMSE is about 4.6.

When the two numbers are close, the errors are all alike. When the RMSE is much bigger, somewhere there are a few huge errors worth tracking down. Looking at both costs nothing and tells you a lot.

MAE  = mean( |estimate − true| )
RMSE = sqrt( mean( (estimate − true)² ) )
(02)

The fake model to beat

The dumbest model for a regression always answers with the average of the labels. It doesn't look at the input, and it still has its own MAE. Every real model has to beat it, and the gap between the two tells you how much it learned.

There's a number that makes this comparison on its own, called R squared. It's 1 if the model is never wrong, 0 if it does as well as the fake model, and below zero if it does worse. In the lab, next to the MAE you'll also see the fake model's, so you can compare them right away.

(03)

Forecasts your phone already makes

Your phone has been making forecasts over time for years. On iPhone, Optimized Battery Charging learns what time you usually unplug the phone and holds the battery at 80 percent until shortly before. Apple says the learning happens on the device.

These forecasts rely on rhythms that repeat, like the day and the week. That's why the most useful features are the hour of the day and the day of the week, even before past values. A small model with those two pieces of information often beats a big one that doesn't have them.

(Try it on your phone)

The metronome's rhythm


In the lab you train a model that estimates how fast the rhythm is as you shake the phone. It takes ten minutes and a metronome, and a free app will do.

  1. Open the lab, choose the Motion input and the Number task.
  2. For each rhythm, 60, 90, 120 and 150 beats per minute, first type the beats in the value field. Then press Continuous recording and shake the phone in time for 10 seconds. Do it twice for each rhythm.
  3. Press Train, then look at the average error in Evaluate.
  4. In Use, press Try it live and shake at 100 beats, a rhythm the model has never seen. Watch the estimate.
  5. Try 200 beats, out of range, and compare the error.
Open the lab →
(Quiz)

4 questions to close the lesson.

When you have answered them all, the lesson counts as done and its stone on the map turns yellow. Answering is what counts, not the score.


  1. (01)

    What changes in the network when the answer is a number instead of a class?

  2. (02)

    The estimates are 92, 85 and 100, and the true values are 90, 90 and 90. What's the MAE?

  3. (03)

    You trained the model between 60 and 150 beats. What happens at 200?

  4. (04)

    Nine times out of ten, the error on the test examples is within 8 beats. How do you give an estimate of 110?

To close the lesson, answer the quiz

← Noticing what's unusual The course review Back to the map
(Next lesson · 05.01) Words become numbers