Find a course

Module 1: What AI Is and How Machines LearnLesson 2 of 1112 min

How Machines Learn from Data

See how machine learning turns examples into a model using features and labels, and compare supervised, unsupervised and reinforcement learning.

Step 1 of 11Learn

Learning from examples

Imagine teaching a computer to sort fruit into apples and oranges. Instead of writing rules, you collect examples. For each fruit you measure a few things: its weight, its color on a scale from red to orange, and how bumpy its skin is. These measurable properties are called features. You also write down the correct answer for each one, apple or orange. That answer is the label.

Weight (g)Color (0 red, 10 orange)Bumpiness (0 to 10)Label
15021apple
14087orange
17032apple
13098orange

A collection like this is training data. A machine learning algorithm studies it and builds a model: a mathematical rule, discovered from the data, that maps features to labels. Here it might discover that high color scores and bumpy skin go with oranges.

Now give the model a fruit it has never seen: 145 g, color 7, bumpiness 6. It predicts orange. That's the whole idea of machine learning: learn from labeled examples, then predict labels for new ones.

Real systems work the same way at a vastly larger scale. A spam filter's features might include the words in an email, the number of links and the sender's history, learned from millions of emails people marked as spam or not spam.

Step 2 of 11Try the calculator

A tiny fruit classifier (illustrative)

This toy model gives each fruit an "orange score" from two features. The weights were chosen by hand for the demo; a real model would learn them from the labeled table. A positive score means the model says orange, negative means apple. Try the rows from the table, then invent your own fruit.

Orange score (positive = orange)
3

Step 3 of 11Practice · Match the pairs

In a model that predicts whether a student will enjoy a movie, match each item to its role.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. The movie's genre and length
  2. Whether the student actually liked it
  3. Thousands of past ratings with their answers
  4. The learned rule used to predict for new movies

Step 4 of 11Learn

Three ways machines learn

Machine learning comes in three main styles.

Supervised learning learns from examples with labels, like the fruit table. Someone has to supply the right answers: photos tagged "cat," emails marked "spam," houses with their sale prices. Most practical AI uses supervised learning: image recognition, spam filters, speech recognition and medical image analysis.

Unsupervised learning works with data that has no labels and looks for structure on its own, such as groups (clusters) of similar items. A music service might discover that listeners naturally fall into groups with similar tastes, without anyone defining those groups in advance. Shops use it to find customers with similar buying habits.

Reinforcement learning learns by trial and error. An agent takes actions in an environment and receives rewards or penalties, gradually learning which actions lead to the most reward. Game-playing AIs learn this way, playing millions of games against themselves. Robots can learn to walk this way in simulations, being rewarded for moving forward without falling.

Many modern systems combine styles. Chatbots, for example, first learn patterns from huge amounts of text, then are fine-tuned with human feedback that rewards helpful, accurate answers, a form of reinforcement learning.

Step 5 of 11Compare

Three ways machines learn

AspectSupervisedUnsupervisedReinforcement
DataExamples with labelsExamples without labelsNo examples: actions and rewards
GoalPredict the label for new casesFind groups and structureLearn which actions earn the most reward
ExampleSpam filter, photo taggingGrouping listeners with similar tasteGame-playing AI, robot learning to walk

Step 6 of 11Practice · Sort into groups

Which type of machine learning fits each situation?

Tap an item, then tap its group (or drag it there).

Step 7 of 11Learn

Learning is adjusting

What does it actually mean for a computer to "learn"? At its core, the model has many adjustable numbers, called parameters, and learning means tuning them to make fewer mistakes.

Here's the loop, repeated over and over during training:

  1. The model makes a prediction for a training example.
  2. The prediction is compared with the correct label, and the size of the error is measured.
  3. The parameters are nudged slightly in the direction that would have made the error smaller.

After thousands or millions of rounds, the parameters settle on values that work well across the training data. A simple model might have a handful of parameters; a large chatbot model has billions.

A good comparison is learning to shoot free throws. You shoot, see whether the ball went long or short, and adjust your aim a little. You don't calculate physics equations; you just keep correcting based on feedback. After enough practice, you're accurate. Machine learning is a mathematical version of that practice loop.

Notice what this means: a model is only as good as its examples. If the training data is too small, unrepresentative or full of wrong labels, the model will faithfully learn the wrong lessons.

Step 8 of 11Explore

Watch the error shrink during training (illustrative)

In this simplified picture, each training round removes a fixed share of the remaining error. The learning rate controls how big each nudge is. Real training curves are bumpier, and a learning rate that is too large can make training unstable, which this simple model does not show.

020406080100 01020304050
Error after 10 rounds
20.9 %
Error after 50 rounds
0.31 %

Step 9 of 11Practice · Put in order

Put the steps of one round of the machine learning training loop in order.

Drag the items, or use the arrow buttons, to put them in order.

  1. The parameters are adjusted slightly to reduce the error
  2. The model makes a prediction for a training example
  3. The size of the error is measured
  4. The loop repeats with the next example
  5. The prediction is compared with the correct label

Step 10 of 11Note

Step 11 of 11Practice · What would you do?

What would you do?

A team trains a model to recognize dogs using 10,000 labeled photos. Almost all of the photos show dogs on grass in sunny parks. The model performs badly on photos of dogs indoors. What's the most likely reason?