Académique Documents
Professionnel Documents
Culture Documents
Apprentissage Automatique
IGE 42 - 5éme année (2021-2022)
Spécialité : Télécoms et Technologies Numériques
Dr. FEZZA S.
Objectifs
• 2 grands objectifs du cours
apprendre les fondements théoriques
savoir les mettre en pratique
Machine Learning 2
1
28/11/2021
Autres cours
• Liens avec d’autres cours
• Algèbre
• Probabilités et statistiques
• Analyse de données
Machine Learning 3
TP
• Homework
• Code (avec commentaries)
• Rapport (5 pages max)
• Pour chaque chapitre
• Binôme
• fezza.student@gmail.com
© FEZZA S. v21‐22
Machine Learning 4
2
28/11/2021
© FEZZA S. v21‐22
Ressources
Machine Learning 5
Plan
Introduction
Régression
Séparateurs a vaste marge
Arbres de décision
Apprentissage bayésien
Réseaux de neurones artificiels
Modèles de Markov cachés
© FEZZA S. v21‐22
Apprentissage par renforcement
Machine Learning 6
3
28/11/2021
Plan
Introduction
Régression
Séparateurs a vaste marge
Arbres de décision
Apprentissage bayésien
Réseaux de neurones artificiels
Modèles de Markov cachés
© FEZZA S. v21‐22
Apprentissage par renforcement
Machine Learning 7
Objectifs
• Définir AI, ML, DL
• Intérêt du ML
• Critères de performance
Machine Learning 8
4
28/11/2021
© FEZZA S. v21‐22
ML Applications
Machine Learning 9
Artificial intelligence,
machine learning, and deep learning
© FEZZA S. v21‐22
Machine Learning 10
5
28/11/2021
© FEZZA S. v21‐22
Some quotes
Machine Learning 11
History of ML
© FEZZA S. v21‐22
Machine Learning 12
6
28/11/2021
• Le ML a justement été inventé pour venir débloquer la situation 2 (quand on ne connait pas le
calcul), en utilisant une technique audacieuse Laisser la Machine apprendre à partir
d’expériences
Machine Learning 13
• Le ML est donc utilisé quand les données sont abondantes (relativement), mais les
connaissances peu accessibles ou peu développées.
© FEZZA S. v21‐22
Machine Learning 14
7
28/11/2021
Définition du ML
• L’apprentissage automatique ou l’apprentissage par machine (Machine Learning) s'intéresse à
la conception, l'analyse, l'implémentation et l’application de programmes d’ordinateur capables de
s’améliorer, au fil du temps, soit sur la base de leur propre expérience, soit à partir des données
antérieures fournies par d’autres programmes.
A computer program is said to learn from experience E with respect to some task T and some
performance measure P, if its performance on T, as measured by P, improves with experience E.
—Tom Mitchell, 1997
Machine Learning 15
Définition du ML
© FEZZA S. v21‐22
Machine Learning 16
8
28/11/2021
© FEZZA S. v21‐22
Définition du ML
Machine Learning 17
Définition du ML
Task
Image
Classification
© FEZZA S. v21‐22
Machine Learning 18
9
28/11/2021
Définition du ML
Task Experience
Image
Data
Classification
© FEZZA S. v21‐22
Machine Learning 19
Définition du ML
Dog
Image
Classifier
Cat
ML model
Performance Accuracy
measure
Image
Classifier
© FEZZA S. v21‐22
ML model
Machine Learning 20
10
28/11/2021
Définition du ML
Task Experience
Image
Data
Classification Performance
measure
Accuracy
© FEZZA S. v21‐22
Machine Learning 21
Machine Learning 22
11
28/11/2021
Machine Learning 23
MNIST dataset
Machine Learning 24
12
28/11/2021
... et l’algorithme retourne un «programme» capable de généraliser à de nouvelles données
données d’entraînement vs. généralisation
Machine Learning 25
Machine Learning 26
13
28/11/2021
© FEZZA S. v21‐22
Example 2: Spam emails
Machine Learning 27
(model)
• A machine‐learning system is trained rather than explicitly programmed. It’s presented with many
examples relevant to a task, and it finds statistical structure in these examples that eventually allows
© FEZZA S. v21‐22
• Machine Learning is the science of programming computers so they can learn from data.
Machine Learning 28
14
28/11/2021
© FEZZA S. v21‐22
Machine Learning Vs Traditional Programming
Machine Learning 29
• Ces deux piliers sont aussi importants l’un que l’autre. D’une part, aucun algorithme
d’apprentissage ne pourra créer un bon modèle à partir de données qui ne sont pas
pertinentes – c’est le concept garbage in, garbage out qui stipule qu’un algorithme
d’apprentissage auquel on fournit des données de mauvaise qualité ne pourra rien en
faire d’autre que des prédictions de mauvaise qualité. D’autre part, un modèle appris
avec un algorithme inadapté sur des données pertinentes ne pourra pas être de
bonne qualité.
Machine Learning 30
15
28/11/2021
Notations
• Ensemble d’entraînement (training set), entrée (input), cible (target)
= Number of training examples
= ith “input” variable / features
© FEZZA S. v21‐22
= ith “output” variable / “target” variable
Machine Learning 31
Comment apprendre ?
• Mais comment apprendre ?
Pour donner à un ordinateur la capacité d’apprendre, on utilise
des méthodes d’apprentissage qui sont fortement inspirées de la
façon dont nous, les êtres humains, apprenons à faire des
choses. Parmi ces méthodes, on compte :
Machine Learning 32
16
28/11/2021
Supervised Learning
• The idea of supervised learning is that the learning system is given
inputs and told which specific outputs should be associated with
them. We divide up supervised learning based on whether the
outputs are drawn from a small finite set (classification) or a large
finite or continuous set (regression).
Machine Learning 33
Supervised Learning
• The idea of supervised learning is that the learning system is given
inputs and told which specific outputs should be associated with
them. We divide up supervised learning based on whether the
outputs are drawn from a small finite set (classification) or a large
finite or continuous set (regression).
il y a une cible à prédire
(target value, “right answers” given)
Machine Learning 34
17
28/11/2021
Supervised Learning
• L’apprentissage supervisé est lorsqu’on a une cible à prédire
Machine Learning 35
Supervised Learning
Price
Size2
Breast cancer (malignant, benign)
© FEZZA S. v21‐22
Machine Learning 36
18
28/11/2021
Supervised Learning
Machine Learning 37
Supervised Learning
• Par exemple, pour prédire le prix d’un appartement (𝑦), un modèle de ML peut
prendre en compte :
• sa surface (𝒙(𝟏))
• sa localisation (𝒙(2))
• sa qualité (𝒙(3))
• sa proximité avec une école (𝒙(4))
• etc.
Machine Learning 38
19
28/11/2021
Unsupervised Learning
• Unsupervised learning doesn’t involve learning a function from
inputs to outputs based on a set of input‐output pairs. Instead,
one is given a data set and generally expected to find some
patterns or structure inherent in it.
Machine Learning 39
Unsupervised Learning
• Unsupervised learning doesn’t involve learning a function from
inputs to outputs based on a set of input‐output pairs. Instead,
one is given a data set and generally expected to find some
patterns or structure inherent in it.
cible n’est pas fournie
Machine Learning 40
20
28/11/2021
Unsupervised Learning
© FEZZA S. v21‐22
Machine Learning 41
Machine Learning 42
21
28/11/2021
Semi-supervised Learning
• Since labeling data is usually time‐consuming and costly, you will often have
plenty of unlabeled instances, and few labeled instances. Some algorithms can
deal with data that’s partially labeled.
© FEZZA S. v21‐22
Semi‐supervised learning with two classes (triangles and squares): the unlabeled
examples (circles) help classify a new instance (the cross) into the triangle class rather
than the square class, even though it is closer to the labeled squares
Machine Learning 43
Machine Learning 44
22
28/11/2021
© FEZZA S. v21‐22
Quick note
Machine Learning 45
Reinforcement Learning
• Reinforcement Learning is a very different beast. The learning system, called an
agent in this context, can observe the environment, select and perform actions,
and get rewards in return (or penalties in the form of negative rewards. It must
then learn by itself what is the best strategy, called a policy, to get the most
reward over time. A policy defines what action the agent should choose when
it is in a given situation.
Machine Learning 46
23
28/11/2021
Reinforcement Learning
• Reinforcement Learning is a very different beast. The learning system, called an
agent in this context, can observe the environment, select and perform actions,
and get rewards in return (or penalties in the form of negative rewards. It must
then learn by itself what is the best strategy, called a policy, to get the most
reward over time. A policy defines what action the agent should choose when
it is in a given situation.
47
Types of ML
© FEZZA S. v21‐22
Machine Learning 48
24
28/11/2021
Types de problèmes en ML
Yann LeCun: “Most of human and animal learning is
unsupervised learning. If intelligence was a cake, unsupervised
learning would be the cake, supervised learning would be the
icing on the cake, and reinforcement learning would be the
cherry on the cake.”
© FEZZA S. v21‐22
Machine Learning 49
Machine Learning 50
25
28/11/2021
Instance-based learning
• Possibly the most trivial form of learning is simply to learn by heart. If you were to create a spam
filter this way, it would just flag all emails that are identical to emails that have already been flagged
by users—not the worst solution, but certainly not the best.
• Instead of just flagging emails that are identical to known spam emails, your spam filter could be
programmed to also flag emails that are very similar to known spam emails. This requires a
measure of similarity between two emails. A (very basic) similarity measure between two emails
could be to count the number of words they have in common. The system would flag an email as
spam if it has many words in common with a known spam email. This is called instance‐based
learning: the system learns the examples by heart, then generalizes to new cases by using a
similarity measure to compare them to the learned examples (or a subset of them).
© FEZZA S. v21‐22
Machine Learning 51
Model-based learning
• Another way to generalize from a set of examples is to build a model of these examples
and then use that model to make predictions. This is called model‐based learning.
Machine Learning 52
26
28/11/2021
Model-based learning
• For example, suppose you want to know if money makes people happy, so you
download the Better Life Index data from the OECD’s website and stats about gross
domestic product (GDP) per capita from the IMF’s website. Then you join the tables and
sort by GDP per capita.
Does money make people happier?
© FEZZA S. v21‐22
Machine Learning 53
Model-based learning
• There does seem to be a trend here! Although the data is noisy (i.e., partly random), it
looks like life satisfaction goes up more or less linearly as the country’s GDP per capita
increases. So you decide to model life satisfaction as a linear function of GDP per capita.
This step is called model selection: you selected a linear model of life satisfaction with
just one attribute, GDP per capita
© FEZZA S. v21‐22
Machine Learning 54
27
28/11/2021
Model-based learning
• A simple linear model
© FEZZA S. v21‐22
Machine Learning 55
Model-based learning
• A simple linear model
© FEZZA S. v21‐22
Machine Learning 56
28
28/11/2021
© FEZZA S. v21‐22
Minimisation de perte (coût, erreur)
Machine Learning 57
Machine Learning 58
29
28/11/2021
Model-based learning
• Model selection consists in choosing the type of model and fully specifying its
architecture. Training a model means running an algorithm to find the model
parameters that will make it best fit the training data (and hopefully make good
predictions on new data).
© FEZZA S. v21‐22
Machine Learning 59
Model-based learning
• Model selection consists in choosing the type of model and fully specifying its
architecture. Training a model means running an algorithm to find the model
parameters that will make it best fit the training data (and hopefully make good
predictions on new data).
© FEZZA S. v21‐22
Machine Learning 60
30
28/11/2021
Model-based learning
• You are finally ready to run the model to make predictions. For example, say you want
to know how happy Cypriots are, and the OECD data does not have the answer.
Fortunately, you can use your model to make a good prediction: you look up Cyprus’s
GDP per capita, find $22,587, and then apply your model and find that life satisfaction is
likely to be somewhere around 4.85 + 22,587 × 4.91 × 10‐5 = 5.96.
© FEZZA S. v21‐22
Machine Learning 61
Main Challenges of ML
Machine Learning 62
31
28/11/2021
Main Challenges of ML
• bad data
• Insufficient Quantity of Training Data
• For a toddler to learn what an apple is, all it takes is for you to point to an apple
and say “apple” (possibly repeating this procedure a few times). Now the child is
able to recognize apples in all sorts of colors and shapes. Genius.
• Machine Learning is not quite there yet; it takes a lot of data for most Machine
Learning algorithms to work properly. Even for very simple problems you typically
need thousands of examples, and for complex problems such as image or speech
recognition you may need millions of examples (unless you can reuse parts of an
existing model).
14 million images
© FEZZA S. v21‐22
Machine Learning 63
Main Challenges of ML
• bad data
• Insufficient Quantity of Training Data
• For a toddler to learn what an apple is, all it takes is for you to point to an apple
and say “apple” (possibly repeating this procedure a few times). Now the child is
able to recognize apples in all sorts of colors and shapes. Genius.
• Machine Learning is not quite there yet; it takes a lot of data for most Machine
Learning algorithms to work properly. Even for very simple problems you typically
need thousands of examples, and for complex problems such as image or speech
recognition you may need millions of examples (unless you can reuse parts of an
existing model).
© FEZZA S. v21‐22
Machine Learning 64
32
28/11/2021
Main Challenges of ML
• bad data
• Insufficient Quantity of Training Data
• For a toddler to learn what an apple is, all it takes is for you to point to an apple
and say “apple” (possibly repeating this procedure a few times). Now the child is
able to recognize apples in all sorts of colors and shapes. Genius.
• Machine Learning is not quite there yet; it takes a lot of data for most Machine
Learning algorithms to work properly. Even for very simple problems you typically
need thousands of examples, and for complex problems such as image or speech
recognition you may need millions of examples (unless you can reuse parts of an
existing model).
© FEZZA S. v21‐22
The importance of data vs. algorithms
Machine Learning 65
Main Challenges of ML
• bad data
• Non representative Training Data
• In order to generalize well, it is crucial that your training data be representative
of the new cases you want to generalize to.
© FEZZA S. v21‐22
Machine Learning 66
33
28/11/2021
Main Challenges of ML
• bad data
• Poor‐Quality Data
• Obviously, if your training data is full of errors, outliers, and noise (e.g., due to
poor quality measurements), it will make it harder for the system to detect the
underlying patterns, so your system is less likely to perform well. It is often well
worth the effort to spend time cleaning up your training data. The truth is, most
data scientists spend a significant part of their time doing just that. The following
are a couple of examples of when you’d want to clean up training data:
• If some instances are clearly outliers, it may help to simply discard them or
try to fix the errors manually.
• If some instances are missing a few features (e.g., 5% of your customers did
not specify their age), you must decide whether you want to ignore this
attribute altogether, ignore these instances, fill in the missing values (e.g.,
with the median age), or train one model with the feature and one model
without it.
© FEZZA S. v21‐22
Machine Learning 67
Main Challenges of ML
• bad data
• Irrelevant Features (garbage in, garbage out)
• Your system will only be capable of learning if the training data contains enough
relevant features and not too many irrelevant ones. A critical part of the success
of a Machine Learning project is coming up with a good set of features to train
on. This process, called feature engineering, involves the following steps:
• Feature selection: selecting the most useful features to train on among existing
features
• Feature extraction: combining existing features to produce a more useful one (as
dimensionality reduction algorithms can help)
• Creating new features by gathering new data
© FEZZA S. v21‐22
Machine Learning 68
34
28/11/2021
Main Challenges of ML
• bad algorithm
• Overfitting the Training Data
• It means that the model performs well on the training data, but it does not
generalize well.
© FEZZA S. v21‐22
Machine Learning 69
Main Challenges of ML
• bad algorithm
• Overfitting the Training Data
• It means that the model performs well on the training data, but it does not
generalize well.
© FEZZA S. v21‐22
Machine Learning 70
35
28/11/2021
Main Challenges of ML
• bad algorithm
• Overfitting the Training Data
• It means that the model performs well on the training data, but it does not
generalize well.
© FEZZA S. v21‐22
Machine Learning 71
Main Challenges of ML
• bad algorithm
• Overfitting the Training Data
Machine Learning 72
36
28/11/2021
Main Challenges of ML
Training Experience
data
Data
Test
data
© FEZZA S. v21‐22
Machine Learning 73
Main Challenges of ML
• bad algorithm
• Underfitting the Training Data
• It occurs when your model is too simple to learn the underlying structure of the
data.
© FEZZA S. v21‐22
Machine Learning 74
37
28/11/2021
Main Challenges of ML
• bad algorithm
• Underfitting the Training Data
• It occurs when your model is too simple to learn the underlying structure of the
data.
© FEZZA S. v21‐22
Machine Learning 75
Main Challenges of ML
© FEZZA S. v21‐22
Machine Learning 76
38
28/11/2021
Main Challenges of ML
n=1
y y
© FEZZA S. v21‐22
Machine Learning 77
Main Challenges of ML
y y
© FEZZA S. v21‐22
Machine Learning 78
39
28/11/2021
Main Challenges of ML
n=0 n=1
y y
© FEZZA S. v21‐22
Machine Learning 79
Main Challenges of ML
n=0 n=1
y y
n=9 n=3
y y
© FEZZA S. v21‐22
Machine Learning 80
40
28/11/2021
y y
© FEZZA S. v21‐22
Machine Learning 81
n
Machine Learning 82
41
28/11/2021
Regularization
y y
© FEZZA S. v21‐22
Machine Learning 83
Machine Learning 84
42
28/11/2021
© FEZZA S. v21‐22
Split your data
Machine Learning 85
80% 20%
© FEZZA S. v21‐22
Machine Learning 86
43
28/11/2021
© FEZZA S. v21‐22
Split your data
Machine Learning 87
Machine Learning 88
44
28/11/2021
80% 20%
Test set is only used once!
© FEZZA S. v21‐22
Machine Learning 89
Machine Learning 90
45
28/11/2021
Machine Learning 91
46
28/11/2021
Machine Learning 93
Machine Learning 94
47
28/11/2021
© FEZZA S. v21‐22
Hyperparameter Tuning and Model Selection
Machine Learning 95
Performance Measures
• Classification
• we want to assess a given classifier that learns how to predict y from x
Machine Learning 96
48
28/11/2021
Performance Measures
• Classification
• we want to assess a given classifier that learns how to predict y from x
Machine Learning 97
Performance Measures
• Classification
• The following metrics are commonly used to assess the performance of
classification models:
© FEZZA S. v21‐22
Machine Learning 98
49
28/11/2021
Performance Measures
• Classification
• The following metrics are commonly used to assess the performance of
classification models:
© FEZZA S. v21‐22
Machine Learning 99
Performance Measures
• Classification
• The following metrics are commonly used to assess the performance of
classification models:
© FEZZA S. v21‐22
Machine Learning 100
50
28/11/2021
Performance Measures
• Classification
• The following metrics are commonly used to assess the performance of
classification models:
© FEZZA S. v21‐22
Machine Learning 101
Performance Measures
• Classification
• ROC – The receiver operating curve, also noted ROC, is the plot of TPR versus
FPR by varying the threshold.
© FEZZA S. v21‐22
Machine Learning 102
51
28/11/2021
Performance Measures
• Classification
• AUC – The area under the receiving operating curve, also noted AUC or AUROC,
is the area below the ROC.
© FEZZA S. v21‐22
Machine Learning 103
Performance Measures
• Classification
• AUC – The area under the receiving operating curve, also noted AUC or AUROC,
is the area below the ROC.
© FEZZA S. v21‐22
Machine Learning 104
52
28/11/2021
Performance Measures
• Classification
• AUC – The area under the receiving operating curve, also noted AUC or AUROC,
is the area below the ROC.
Label + + +
Score 0.9 0.8 0.6 0.4 0.3 0.1
Machine Learning 105
Performance Measures
• Classification
• AUC – The area under the receiving operating curve, also noted AUC or AUROC,
is the area below the ROC.
Label + ‐ + + ‐ ‐
Score 0.9 0.8 0.6 0.4 0.3 0.1
Machine Learning 106
53
28/11/2021
Performance Measures
• Regression
• Basic metrics – Given a regression model f, the following metrics are commonly
used to assess the performance of the model:
© FEZZA S. v21‐22
Machine Learning 107
54