Aller au contenu principal
Traduire le contenu

Pour lire le contenu dans une autre langue, utilisez la commande Traduire la page de votre navigateur (clic droit ou menu du navigateur). Choisissez votre langue et, si proposé, activez la traduction automatique. Le menu des langues du site change la navigation, pas le texte original. Les activités interactives peuvent rester dans leur langue d’origine.

AIFondamentaux, IntermédiaireDurée estimée: 20 minMis à jour le 25 novembre 2026

Supervised vs. Unsupervised Learning: A Visual Guide for Beginners

How do machines learn from data? Some machine learning models learn from examples with known answers, while others discover patterns without predefined labels. This lesson introduces supervised and unsupervised learning through visual explanations, worked examples, and interactive experiments. You will explore classification, regression, and clustering, understand how each method works, and learn how to choose an appropriate approach for different problems.

Visual comparison of supervised and unsupervised machine learning, showing labeled data and discovered clusters.

Objectifs d’apprentissage

  • Understand the difference between supervised and unsupervised learning.
  • Identify features and target labels in a dataset.
  • Distinguish labeled data from unlabeled data.
  • Explain how supervised learning models make predictions.
  • Understand classification and categorical predictions.
  • Understand regression and numerical predictions.
  • Explain how clustering discovers groups of similar observations.
  • Explore the basic principles of nearest-neighbor classification.
  • Interpret a simple linear regression model.
  • Understand the assignment and update steps of k-means clustering.
  • Choose an appropriate machine learning method for a given problem.
  • Recognize the limitations of machine learning predictions and discovered patterns.

Introduction

Imagine sorting a basket of fruit. A teacher could show you examples labeled apple and orange, then ask you to identify a new fruit. Alternatively, you could receive a basket without labels and discover groups based on similarities. These approaches illustrate two major types of machine learning: supervised and unsupervised learning.

Machine learning uses data to learn patterns rather than requiring a programmer to specify every decision. In this lesson, you will explore how training examples, target values and similarities lead to different kinds of predictions and discoveries.

Learning objectives

  • Distinguish features from target labels.
  • Explain supervised and unsupervised learning.
  • Distinguish classification, regression and clustering.
  • Interpret simple model predictions and limitations.

1. Understanding training data

A dataset is a collection of examples. Each row represents an observation. A feature is an input characteristic, such as a fruit's mass or diameter. A target is the outcome a supervised model is trained to predict.

Mass (g)Diameter (cm)Target category
1206Apple
1407Apple
1808Orange
2009Orange

This fictional dataset is labeled because the target category is known. Removing the category column gives an unlabeled dataset for a clustering task. In real life, fruit categories overlap: these measurements alone cannot reliably identify every fruit.

2. Supervised learning

Supervised learning trains a model using inputs paired with known targets. The model learns a relationship between the inputs and targets, then predicts targets for new inputs. The word supervised refers to the training signal, not necessarily a person watching the computer.

  1. Collect examples with known targets.
  2. Separate training examples from test examples.
  3. Fit a model using the training data.
  4. Evaluate predictions on unseen test data.
  5. Use the model cautiously on new examples.

A model that memorizes training examples but performs poorly on new examples is overfitting. Good performance on training data alone does not establish reliability.

3. Classification: predicting categories

Classification predicts a discrete category, such as apple or orange. A simple nearest-neighbor classifier can compare a new example with labeled training examples and copy the label of the closest example.

Worked example

Use only mass for this simplified demonstration. A new fruit weighs 155 g. Its distances from the four training masses are 35, 15, 25 and 45 g. The closest training example weighs 140 g and is labeled Apple. The predicted category is therefore Apple. This is a prediction, not proof of the fruit's identity.

Interactive experiment 1

Change the mass of the new fruit. Observe which training example is closest and how the predicted category changes. At equal distances, this demonstration selects the first example in the displayed dataset.

Fruit mass (g)

At 155 g, the nearest example is 140 g: Apple.

Green circles: Apple. Blue squares: Orange. Vertical marker: new fruit.

4. Regression: predicting numbers

Regression predicts a numerical target, such as temperature or the amount of water used by a garden. Unlike classification, the output is a quantity rather than a category.

Watering duration (minutes)Water used (liters)
12
24
36
48

Worked example

In this idealized dataset, water use increases by 2 liters per minute. A linear regression model fitted to these exact observations has slope 2 and intercept 0. For 3.5 minutes, the predicted amount is 2 × 3.5 = 7 liters. Real measurements may contain noise, and the fitted line may not pass through every observation.

Interactive experiment 2

Watering duration (minutes)

3.5 minutes → 7 liters

Blue points: observations. Green line: fitted model. Orange point: prediction.

The slider stays inside the observed range. Predicting beyond that range is extrapolation and may be less reliable.

5. Unsupervised learning

Unsupervised learning searches for structure in data without a supplied target label. It can reveal groups, unusual observations or useful representations. It does not automatically discover the true meaning of every group. People must interpret and validate the results.

6. Clustering: discovering groups

Clustering groups observations according to a chosen similarity measure. For example, a library might explore groups of fictional books based on page count and number of illustrations. No category labels are supplied.

Worked example: one-dimensional k-means

Consider six fictional books with page counts 20, 30, 40, 100, 110 and 120. Choose two initial centers: 20 and 120. Assign each book to its nearest center. The first group contains 20, 30 and 40; the second contains 100, 110 and 120. Update the centers by calculating the group means: (20 + 30 + 40) ÷ 3 = 30 and (100 + 110 + 120) ÷ 3 = 110. Reassign the books. The groups do not change, so the algorithm has converged for this example.

Interactive experiment 3

Press Next iteration to assign books and update the centers. Reset to repeat the process. The number of clusters is fixed at two for this demonstration.

Initial centers: 20 and 120 pages. No assignments yet.

Gray: unassigned. Green and blue: cluster membership. Vertical markers: centers.

Changing the features, their scales, the number of clusters or initial centers can change the result. Cluster numbers are identifiers, not known target labels.

7. Comparing the methods

QuestionClassificationRegressionClustering
Learning typeSupervisedSupervisedUnsupervised
Known target?YesYesNo
OutputCategoryNumberGroup assignment
ExampleFruit categoryWater useSimilar books

To choose a method, first ask whether known target values are available. If they are, ask whether the desired output is categorical or numerical. If no target is supplied and the goal is to discover groups, clustering may be appropriate. Other unsupervised tasks also exist, such as dimensionality reduction.

8. Common mistakes and responsible use

  • Do not confuse numerical category identifiers with numerical regression targets.
  • Do not evaluate a supervised model only on its training data.
  • Do not assume clusters represent natural or meaningful categories.
  • Do not assume a model trained on a tiny fictional dataset will generalize to real data.
  • Use suitable features and check data quality. Avoid unnecessary personal information.

9. Practice exercises

  1. A dataset contains plant measurements and known species. Identify the learning type and task.
    Solution

    Supervised classification: the known species is a categorical target.

  2. Predict the number of liters used in a garden from watering duration. Identify the task.
    Solution

    Supervised regression, assuming training examples include measured water use. The target is numerical.

  3. Group unlabeled books by their page counts. Identify the task.
    Solution

    Unsupervised clustering: the goal is to discover similar groups without supplied target labels.

  4. Using the fruit dataset, predict the category of a 175 g fruit with one nearest neighbor.
    Solution

    The distances are 55, 35, 5 and 25 g. The closest example is 180 g, labeled Orange. Predict Orange.

  5. Using the fitted water-use model, predict water use for 2.5 minutes.
    Solution

    Multiply 2 liters per minute by 2.5 minutes to obtain 5 liters.

  6. Find the mean of the cluster containing 100, 110 and 120 pages.
    Solution

    Add the values to get 330, then divide by 3. The updated center is 110 pages.

  7. A classifier scores perfectly on its training examples. Is it necessarily reliable on new data?
    Solution

    No. It may have memorized the training examples. Evaluate it using unseen test data.

  8. A clustering algorithm produces two groups. Does this prove that exactly two real categories exist?
    Solution

    No. The result depends on the algorithm, features and settings. The groups require interpretation and validation.

Key takeaways

  • Supervised learning uses known targets.
  • Classification predicts categories; regression predicts numerical values.
  • Unsupervised learning explores structure without supplied targets.
  • Clustering groups similar observations.
  • All model results require careful interpretation and evaluation.

Définitions

Machine Learning

A branch of artificial intelligence that uses data to learn patterns and perform tasks such as prediction or pattern discovery.

Dataset

An organized collection of observations used for analysis, training, or evaluation.

Feature

An input characteristic or variable used by a machine learning model.

Target

The known outcome that a supervised learning model is trained to predict.

Labeled Data

Data containing input features paired with known target values.

Unlabeled Data

Data containing observations without supplied target labels for the learning task.

Supervised Learning

A machine learning approach that learns relationships between input features and known target values.

Unsupervised Learning

A machine learning approach that explores patterns and structure without supplied target labels.

Classification

A supervised learning task that predicts a discrete category.

Regression

A supervised learning task that predicts a numerical target.

Clustering

An unsupervised learning task that groups observations according to a chosen measure of similarity.

Nearest Neighbor

A method that makes predictions using nearby training observations according to a distance measure.

Centroid

The mean position of the observations assigned to a cluster in k-means clustering.

Training Data

The examples used to fit a machine learning model.

Test Data

Separate examples used to evaluate a trained model on previously unseen observations.

Overfitting

A situation in which a model learns training-specific patterns or noise and performs poorly on new data.

Generalization

The ability of a trained model to perform well on previously unseen data.

Exemples rédigés

Identifying Features and Labels

A fruit dataset contains mass, diameter, and known fruit category. Identify the features and target.

Mass and diameter are input features because they describe each fruit. The known fruit category is the target because it is the outcome the model learns to predict.

Recognizing a Classification Problem

A model predicts whether an image contains a cat or a dog using labeled training images.

The training images have known target labels. The output is a category rather than a numerical quantity. Therefore, this is supervised classification.

Nearest-Neighbor Classification

Training examples have masses of 120 g and 140 g for apples, and 180 g and 200 g for oranges. Predict the category of a 155 g fruit using one nearest neighbor.

Calculate the absolute distances: 35, 15, 25, and 45 g. The smallest distance is 15 g, corresponding to the 140 g apple. The predicted category is Apple. This prediction is not proof of the fruit's actual identity.

Predicting a Numerical Value

A fitted model predicts water usage using y = 2x, where x is watering duration in minutes. Predict water usage for 3.5 minutes.

Substitute 3.5 into the model. Multiply 2 by 3.5 to obtain 7 liters. This is regression because the predicted target is numerical.

Recognizing Unsupervised Learning

A library groups books according to page count and number of illustrations without providing category labels.

The dataset contains input features but no supplied target labels. The goal is to discover groups of similar observations. Therefore, the task is unsupervised clustering.

Updating K-Means Cluster Centers

Two clusters contain the values 20, 30, 40 and 100, 110, 120. Calculate their updated centers.

For the first cluster, add 20 + 30 + 40 = 90 and divide by 3 to obtain 30. For the second cluster, add 100 + 110 + 120 = 330 and divide by 3 to obtain 110. The updated centers are 30 and 110.

Evaluating Model Reliability

A classifier predicts every training example correctly. Does this guarantee accurate predictions on new examples?

No. The model may have memorized the training examples. Its ability to generalize must be evaluated using separate, previously unseen test data.

Erreurs fréquentes à éviter

  • Confusing supervised learning with continuous human supervision.
  • Confusing input features with target labels.
  • Assuming that all machine learning datasets require target labels.
  • Confusing classification with regression.
  • Treating numerical category identifiers as regression targets.
  • Assuming that clustering and classification are the same task.
  • Believing that discovered clusters always represent meaningful real-world categories.
  • Evaluating a supervised model only on its training data.
  • Assuming that perfect training accuracy guarantees reliable predictions.
  • Ignoring the influence of feature selection and feature scaling.
  • Treating model predictions as guaranteed facts.
  • Assuming that simplified educational datasets represent real-world complexity.

Exercices d’application

Identify the Learning Method

A dataset contains plant measurements and known plant species. A model predicts the species of a new plant. Identify the learning method and task.

Indice: Are the target values known? Is the prediction a category?

Afficher la correction

The dataset contains known species labels, and the model predicts a category. This is supervised classification.

Classification or Regression?

A model learns from watering durations and measured water usage to predict the number of liters used.

Indice: Determine whether the target is categorical or numerical.

Afficher la correction

The target is a numerical quantity, so the task is supervised regression.

Discovering Groups

A library groups books using page counts without supplying category labels. Identify the learning method.

Indice: Does the dataset provide known target labels?

Afficher la correction

No target labels are supplied. The goal is to discover groups of similar observations. This is unsupervised clustering.

Predict a Fruit Category

Apples have training masses of 120 g and 140 g. Oranges have training masses of 180 g and 200 g. Predict the category of a 175 g fruit using one nearest neighbor.

Indice: Calculate the absolute distance from 175 g to each training mass.

Afficher la correction

The distances are 55, 35, 5, and 25 g. The closest training observation is the 180 g orange. The predicted category is Orange.

Apply a Regression Model

The water usage model is y = 2x. Predict the amount of water used in 2.5 minutes.

Indice: Substitute 2.5 for x.

Afficher la correction

Multiply 2 by 2.5. The predicted water usage is 5 liters.

Calculate a Cluster Center

A cluster contains three books with 100, 110, and 120 pages. Calculate the centroid.

Indice: The centroid is the arithmetic mean.

Afficher la correction

Add the page counts: 100 + 110 + 120 = 330. Divide by 3. The centroid is 110 pages.

Understand Overfitting

A model achieves perfect accuracy on its training examples. Is it necessarily reliable on new examples?

Indice: Consider the difference between memorization and generalization.

Afficher la correction

No. The model may have memorized its training examples. Separate test data is required to evaluate its ability to generalize.

Interpret Clustering Results

A clustering algorithm produces two groups. Does this prove that exactly two meaningful real-world categories exist?

Indice: Think about how the features and algorithm settings affect the result.

Afficher la correction

No. The discovered groups depend on the selected features, distance measure, algorithm, and settings. Their meaning must be interpreted and validated.

Points clés

  • Machine learning uses data to learn patterns and relationships.
  • Features describe observations and provide model inputs.
  • Supervised learning requires known target values.
  • Classification predicts discrete categories.
  • Regression predicts numerical quantities.
  • Unsupervised learning explores data without supplied target labels.
  • Clustering groups observations according to similarity.
  • Nearest-neighbor classification uses distances to labeled training examples.
  • K-means clustering alternates between assigning observations and updating cluster centers.
  • Training performance alone does not establish model reliability.
  • Discovered clusters require interpretation and validation.
  • The appropriate learning method depends on the available data and the objective.

Pour aller plus loin

Leçon liée

What Is Generative AI? A Beginner’s Guide with Interactive Demos

Lire la leçon