Lesson 4 of 5 · Open

Training and testing

Memorized, or found the pattern? Only new examples can tell.

Imagine you are studying for an exam with old problems that come with their solutions. After a week you get every one of them right. Have you understood the material, or do you just know these solutions by heart? That only shows on problems you have never seen before.

A learning system, that is, a program that learns from examples, is in the same position. It gets many examples, each with the right answer, such as photos marked cat or dog. It looks for a pattern in them on its own. This phase is called training, and the examples used for it are the training data.

A flawless training run proves little

After training, a system often gets almost all of its training data right. That proves little, because it has already seen these examples together with their answers. It may simply have memorized them without finding the pattern. Then it is right on familiar examples and often wrong on new ones.

Experts call this overfitting: the system has adapted too closely to its training data. You cannot tell from the outside. You have to test it.

Overfitting: memorized instead of understood. Memory only helps with examples that were there before.

Some examples are held back

That is why part of the examples is set aside before training. This part is the test data. The system never gets to see it during training. Only afterward does it have to sort these examples, without knowing the answers. Because you know the right answers, you can count how often it is right. The process in four steps:

  • Collect examples, each with the right answer.
  • Set part of them aside as test data.
  • Train the system on the rest.
  • Have the system sort the test data and count how often it is right.

A test is only fair if not a single test example appeared in training. Familiar examples in a new order are still familiar. Part of the training data is not new to the system either. That even holds for examples it got wrong in training: it has seen them all the same. Even a few familiar examples in the test can make the result look better than it is.

QuestionTraining dataTest data
What is it for?for learningfor testing
When does the system see it?during training, with the answersonly on the test, without the answers
What does the result show?what it can do with familiar exampleswhat it can do with new examples

Turning the test into a number

You sum up the result of the test in one number, the accuracy. It is a share: the number of correct answers on the test, divided by the number of all answers on the test. It is often given in percent, which means out of a hundred. To get there, you raise the fraction to higher terms so that the denominator is 100, when that works.

Example

Ten new photos

A system was trained on 10 animal photos and sorts all 10 correctly. On the test it gets 10 photos it has never seen. It sorts 6 of them correctly.

  1. Correct answers on the test: 6
  2. All answers on the test: 10
  3. Accuracy: 6 : 10 = six tenths = three fifths
  4. In percent: six tenths = 60 over 100, which is 60%

Example

A spam filter

A spam filter is supposed to weed out unwanted advertising emails. It was trained on 2,000 emails and sorts all 2,000 correctly. Then it gets 50 new emails and sorts 45 of them correctly. How accurate is it?

  1. Only the new emails count: 45 of 50 are correct.
  2. Accuracy: 45 : 50 = 45 over 50 = nine tenths
  3. In percent: 45 over 50 = 90 over 100, which is 90%
  4. So with new emails, you can expect it to sort about 90% correctly.

Typical mistake

Taking the training result as the accuracy. For the spam filter that would be 2,000 of 2,000, or 100%. That cannot be right: the filter made mistakes on the new emails. It already knew the emails from training together with their answers, just as you knew the old exam problems with their solutions.

Remember

A system is tested on examples it never saw during training. Accuracy is correct answers divided by all answers.

Tasks

Three tasks complete the lesson. The order does not matter, the text above stays where it is.

Task 1 · Fill in

A plant app shines in training and fails on new photos. Fill in the words.

Tap a word, it goes into the marked gap.

The app has only memorized its instead of finding the pattern. So in training it is almost always . On photos it is often wrong. Experts call this .

Task 2 · Input

On a test, a system gives 24 answers, and 16 of them are correct. Give the accuracy in lowest terms.

Enter the result.

Accuracy =

Task 3 · Sorting

A system was trained on photos of traffic signs. What makes a fair test?

Drag every card into its group, or tap the group.

6 cards left

Photos that were only taken after training

Go deeper

Three more tasks, optional. They do not count for completing the lesson.

Task 4 · Input · optional

An app recognizes all 600 bird calls from training, but only 22 of 25 new ones. What is its accuracy in percent?

Enter the result.

Accuracy =%

Task 5 · Choice · optional

Two systems, same training, same test on new images. Which one do you put to use, and why?

One answer is right.

Task 6 · Several right · optional

A system scores 100% in training and 58% on a test with new examples. Which statements are true?

Several answers are right. Pick all of them.

Back to the chapter