Skip to main content

Teaching Machines with Examples: Understanding Supervised Learning

Updated 12 min readMarkdown
Part of seriesMachine Learning, From the Ground Up
Teaching Machines with Examples: Understanding Supervised Learning

Suppose you want to teach a child how to recognise different types of fruits.

You wouldn't start by giving them a complicated explanation of what makes a fruit an apple, an orange, or a banana. Instead, you'd probably show them pictures of different fruits and tell them what each one is.

You might show them an apple and say, "This is an apple."

Then an orange: "This is an orange."

You repeat this with more examples until they begin to recognise what makes an apple different from an orange.

Eventually, you show them a fruit they've never seen before and ask them to identify it.

They might get it right. They might get it wrong. But they've had examples to learn from, and those examples help them make a decision.

Now, what if we could teach a computer in a similar way?

What if, instead of explicitly programming every possible decision it could make, we gave it enough examples to learn from?

This is one of the fundamental ideas behind Supervised Learning.

So, what exactly is Supervised Learning?

In our previous article, What Does It Actually Mean for a Machine to Learn?, we explored the idea that a machine can learn patterns from data and use those patterns to make predictions.

But there's an important question we haven't answered yet:

Where does the machine get the information it needs to learn what a correct prediction looks like?

One way is through supervised learning.

Supervised Learning is a type of Machine Learning where we train a model using examples that already contain the correct answers.

💡

A model is the mathematical system that learns relationships from the data we provide. It is what we eventually use to make predictions.

Let's break that down.

When we say train, we mean allowing a machine learning model to learn from examples.

And when we say the examples contain the correct answers, we mean that for every example we provide, we already know the outcome we want the model to learn to predict.

Think about our fruit example.

We don't just show the computer pictures of fruits. We also tell it what each picture represents.

We give it a picture of an apple and label it "Apple". We give it a picture of a banana and label it "Banana".

The computer uses these examples to learn patterns that help it distinguish between different fruits.

That's the basic idea behind supervised learning.

But let's move away from fruits for a moment and use an example we'll follow throughout this article.

Let's teach a machine how to estimate house prices

Imagine you're building a system that can estimate how much a house should cost.

You have access to information about houses that have already been sold. For each house, you know things like its size, the number of bedrooms, its location, and how much it was sold for.

You could organise some of that information into a table:

House Bedrooms Size Selling Price
A 2 80 sqm ₦25 million
B 3 120 sqm ₦40 million
C 4 180 sqm ₦65 million
D 5 220 sqm ₦85 million

Now, imagine showing this table to a machine learning model.

What do you expect it to learn?

Perhaps it will discover that larger houses tend to sell for more. It might also discover that houses with more bedrooms tend to have higher selling prices.

These are relationships in the data that could help it estimate the price of another house.

Of course, the actual relationship between house prices and these features can be much more complicated. Location, neighbourhood, property condition, and several other factors can influence the price.

But that's not our concern just yet.

What matters is that we've given the machine examples of houses alongside their actual selling prices.

We've given it something to learn from.

And this brings us to two important concepts in Machine Learning: features and labels.

Understanding Features and Labels

Before a machine learning model can learn from data, we need to represent that data in a way it can work with.

Let's return to our house-price table.

Every row represents a house, while each column tells us something about that house.

Some columns describe the house. Another column tells us the outcome we're interested in predicting.

In Machine Learning, we call these features and labels.

What are Features?

Features are the pieces of information we provide to a model to help it make a prediction.

In our house-price example, the features include:

  • Number of bedrooms.
  • Size of the house.
  • Location.
  • Number of bathrooms.

These are the characteristics the model can use to estimate how much a house is worth.

Think of features as the clues we give the machine.

The more useful information we provide, the better opportunity the model has to learn meaningful relationships.

What are Labels?

A label is the correct answer associated with an example in our training data.

Remember that we're trying to build a system that estimates house prices.

So, for every house in our dataset, we already know how much it was actually sold for.

That selling price is our label.

Let's look at the table again:

Bedrooms Size Selling Price
2 80 sqm ₦25m
3 120 sqm ₦40m
4 180 sqm ₦65m
5 220 sqm ₦85m

The first two columns contain our features, while the last column contains the label.

In simple terms:

  • Features: What the model uses to make a prediction.
  • Labels: The answers the model learns to predict.

This distinction is important because it helps us understand what we're actually asking a machine learning model to do.

We're not just throwing random information at a computer and hoping it figures something out. We're providing information and showing it the outcome associated with that information.

How does the machine actually learn?

So far, we've established that supervised learning involves giving a model examples with known answers.

But what happens after we provide those examples?

How does a machine go from looking at a table of houses and their selling prices to estimating the price of a house it has never encountered?

Let's walk through it.

1. We provide the training data

First, we give the model our dataset.

This dataset contains examples of houses, their features, and their corresponding selling prices.

Because we already know the correct selling price for each house, the model has something to learn from.

This collection of examples is what we call training data.

2. The model makes predictions

Next, the model examines the information we've provided and attempts to learn the relationship between the features and the selling prices.

During training, it uses what it has learned so far to make predictions.

Its initial predictions might be quite far from the actual selling prices.

That's perfectly fine. It hasn't learned much yet.

3. We compare its predictions with the actual answers

Remember, we already know how much each house was sold for.

This means we can compare the model's predictions with the actual selling prices.

For example, suppose the actual selling price of a house was ₦40 million, but the model predicted ₦30 million.

There's a difference between what the model predicted and what actually happened.

This difference gives us information about how wrong the prediction was.

4. The model learns from its mistakes

This is where the learning happens.

The model uses the information from its incorrect predictions to adjust itself and improve its future predictions.

It repeats this process, learning from the examples and adjusting its internal parameters along the way.

These adjustments are part of what we call training.

We'll explore how models measure prediction errors and how they adjust their parameters in later articles. For now, just understand that the model isn't expected to get everything right immediately. It improves through a process of making predictions, measuring errors, and adjusting.

5. We use the trained model to make new predictions

After training, we now have a model that has learned relationships from our examples.

We can give it information about a house whose selling price we don't know and ask it to estimate the price.

For example:

  • Bedrooms: 3
  • Size: 140 sqm
  • Location: Lekki

The model uses the relationships it learned during training to produce an estimated selling price.

Notice something important here.

We didn't give it the actual selling price of this new house. That's the whole point.

We want the model to use what it learned from previous examples to make a prediction about something new.

This ability to make predictions beyond the examples it was trained on is one of the things we're ultimately trying to achieve with Machine Learning.

Not every prediction is about numbers

So far, we've used house-price prediction to understand supervised learning.

But supervised learning isn't limited to predicting how much something costs.

Sometimes, instead of asking a machine to predict a number, we want it to identify which category something belongs to.

This brings us to two common types of supervised learning: Regression and Classification.

Regression: When the answer is a number

Regression is used when we want a model to predict a numerical value.

Our house-price example is a regression problem because the model is trying to estimate a price.

Other examples include:

  • Predicting the temperature for the following day.
  • Estimating how long a delivery will take.
  • Predicting the amount of electricity a building might consume.

In each case, the expected answer is a number.

Classification: When the answer is a category

Classification is used when we want a model to assign an example to a particular category.

Imagine building an email filtering system.

You want the system to identify whether an incoming email is spam or legitimate.

You could train a model using thousands of previously labelled emails.

Some emails are labelled "Spam", while others are labelled "Not Spam".

The model learns patterns from these examples and uses what it has learned to classify new emails.

Other examples include:

  • Identifying whether a transaction is fraudulent or legitimate.
  • Classifying an image as a cat or a dog.
  • Identifying whether a customer is likely to respond positively or negatively to a particular offer.

The difference is quite straightforward:

Regression Classification
Predicts numerical values Predicts categories
House-price estimation Spam detection
Temperature prediction Cat or dog recognition

Both are forms of supervised learning. The difference lies in the kind of answer we're asking the model to predict.

We'll explore both in more detail as the series progresses.

Where do we see Supervised Learning in the real world?

Now that we understand how supervised learning works, let's look at a few places where we encounter it.

Email spam detection

Email providers can train models using emails that have already been labelled as spam or legitimate. The model learns patterns that help it classify incoming emails.

Fraud detection

Financial institutions can use historical transactions labelled as fraudulent or legitimate to train models that identify potentially suspicious transactions.

Medical image analysis

Machine learning models can be trained using medical images labelled by qualified professionals to help identify patterns associated with certain medical conditions.

House-price estimation

Property platforms can use historical property data and selling prices to build models that estimate the value of houses.

There's a common idea connecting all these examples.

The model learns from examples where the correct answers are already known, then uses what it has learned to make predictions about new examples.

That's supervised learning in action.

Does supervised learning always work perfectly?

Not quite.

Remember that our model learns from the examples we provide.

This means the quality of those examples matters.

Imagine training a house-price prediction model using information from only expensive houses in one neighbourhood.

Now, suppose we ask that model to estimate the price of a modest house in a completely different neighbourhood.

It might struggle because the examples it learned from don't adequately represent the kind of house we're asking it to evaluate.

The same problem can happen when our dataset contains incorrect information or labels.

If we provide poor examples, we shouldn't expect the model to magically produce excellent predictions.

This is why collecting good data and preparing it properly are important parts of building Machine Learning systems.

We'll return to this idea when we explore how models are evaluated and why performing well on training data doesn't necessarily mean a model will perform well on new data.

Bringing it all together

Let's go back to where we started.

Remember the idea of teaching a child to recognise fruits by showing them examples?

Supervised learning follows a similar idea.

We provide a machine learning model with examples, alongside the correct answers associated with those examples.

The model learns relationships between the information it receives and the answers we want it to predict.

Once trained, we can use it to make predictions about new examples.

And that's really the foundation of supervised learning.

We've also introduced two important building blocks along the way: features and labels.

Features describe the information we give the model, while labels represent the answers we want it to learn to predict.

In the next article, we'll take a closer look at these two concepts.

We'll explore how computers represent information, what it actually means to turn something like a house, an email, or an image into data, and how that data becomes something a Machine Learning model can learn from.

Because before a machine can learn from information, we first need to understand how that information is represented.

About the author

No comments yet. Be the first to comment.

Machine Learning, From the Ground Up

Part 2 of 2

Machine Learning can seem intimidating when you're first introduced to it. There are algorithms, models, datasets, training, predictions, neural networks, and plenty of unfamiliar terminology. But what do these things actually mean? This series breaks down machine learning from the very beginning. We'll start by understanding what it means for a machine to learn, explore how models are trained, and gradually work our way towards more advanced concepts used in modern AI.

Start from the beginningWhat Does It Actually Mean for a Machine to Learn?Imagine you're building an application that needs to identify whether an email is spam or a legitimate email. At first, you might think of writing a few rules to handle this. For example: If an email