Académique Documents
Professionnel Documents
Culture Documents
Master MLDS
Université ParisDescartes
Lazhar.labiod@parisdescartes.f
1 Université de Paris
Déroulement du cours
2 Université de Paris
Objectif du cours
❑ Initier
les étudiants aux méthodes d’apprentissage
supervisé et leurs mises en application sous
R/Python. ❑ à l’issue du cours, l’étudiant doit
❑Connaître le principe de base et les limites des
différentes méthodes
❑ Savoir les mettre en œuvre
❑ Savoir interpréter les résultats
❑ Savoir choisir la méthode la plus adaptée à l’objectif de l’étude et
à la nature des données
3 Université de Paris
Quelques Références
c BreimanL., Friedman J., Olshen R., Stone C., Classification and Regression Trees,
Chapman & Hall, 1984, 1993, 1998.
c Tufféry S., Data Mining et statistique décisionnelle, Technip, 2005. c
Hardle W., Simar L., Applied Multivariate Statistical Analysis, Springer, 2003. c
4 Université de Paris
Ressources
c Cours
c Machine Learning, Andrew Ng (Stanford University) :
https://www.coursera.org/course/ml
c WikiStat : http://wikistat.fr/
c Logiciels
cR + RStudio : http://www.rstudio.com/
c Python + scikit-learn : http://scikit-learn.org/
c Jeux de donnees
c UC Irvine Machine Learning Repository : http://archive.ics.uci.edu/ml/
c Challenges industriels
c Kaggle: https://www.kaggle.com/
c Datascience.net : https://datascience.net/
c Conferences
c ICML : http://icml.cc/
c NIPS : http://nips.cc/
5 Université de Paris
Plan du cours
c Introduction
• Définitions
• Données
• Démarche
• Méthodes
• Evaluationet comparaison de méthodes
• Exemples sous R
8 Université de Paris
Notations
cx : variables explicatives (espace associé X)
c y : variable à expliquer (espace associé Y)
9 Université de Paris
Apprentissage supervisé
10 Université de Paris
10
Apprentissage supervise
c Ce sont des méthodes prédictives
c Classement : la variable a expliquer (ou cible , réponse, dépendante )
est qualitative
11 Université de Paris
12 Université de Paris
Quelques exemples
c Reconnaissance de la parole
c Credit scoring
Données
Objectif
16 Université de Paris Université Paris Descartes
classification
régression
17 Université de Paris
18 Université de Paris
c Il est nécessaire d'étudier la fiabilité de ces règles pour les comparer et les
appliquer, évaluer les cas de sous apprentissage ou de sur apprentissage
(complexité du modèle). On utilise souvent un deuxième échantillon
indépendant, dit de validation ou de test.
19 Université de
Paris
Sur-apprentissage en régression
c Un modèle trop poussé dans la phase d’apprentissage : c épousetoutes
les fluctuations de l’ échantillon d’apprentissage, c détecte ainsi de fausses liaisons,
c et les applique a tort sur d’autres échantillons
Sur-apprentissage en classification
21
Université de Paris
Démarche
23 Université de Paris
Quatre étapes
c Apprentissage : construction du modèle sur un 1er échantillon
pour lequel on connait la valeur de la variable a expliquer
24 Université de Paris
Démarche
25 Université de Paris
Démarche
c On dispose de différentes stratégies d'apprentissage :
c• Règle majoritaire : à tout objet, on associe la classe k telle que
P(k) est maximale.
26 Université de Paris
Méthodes
27 Université de Paris 27
c Régression logistique
c Sans hypothèse sur les lois Xi/Y, Xi peut être discret, nécessaire absence de
colinéarité entre les Xi
c Méthode très souvent performante
c Méthode la plus utilisée en scoring
c Arbres de décision
c Règles complètement explicites
c Traitent les données hétérogènes, éventuellement manquantes, sans
hypothèses de distribution
c Détection d’interactions et de phénomènes non linéaires
c Mais moindre robustesse
28 Université de Paris
Quelques méthodes classiques
29 Université de Paris
Evaluation et comparaison de méthodes 30 Université de
Paris
c La
robustesse : la méthode être le moins sensible possible
aux fluctuations aléatoires d’apprentissage utilisé et
de certaines variables et aux échantillons
valeurs manquantes, ne pas dépendre de l’échantillon bien
se généraliser a d’autres
c La concision : les règles du modèle doivent être les plus
simples et les moins nombreuses possible
31 Université de Paris
32 Université de Paris
Comparaison de méthodes
c Comment comparer différentes méthodes de classification supervisée?
c On utilisera un échantillon test : le taux de bon classement sera évalué sur un
échantillon test n’ayant pas servi à estimer les règles de classement (découpage éch.
existant en 2/3 apprentissage 1/3 test)
c la prédiction de la classe du ième individu est obtenue sans utiliser cet individu pour
estimer les paramètres du modèle
Comparaison de méthodes
c Comment comparer
différentes méthodes de classification
supervisée ?
34 Université de Paris
Matrice de Confusion
Prédit Total
Y=0 Y=1
Réel Y=0 VN FP N
Y=1 FN VP P
Total N1 P1 n
VP VN
Se(s)= . 1−Sp(s)=1−
.
VP+FN VN+ FP
35 Université de Paris
VP +VN
accuracy= .
VP+ FN +VN + FP
VP +VN
36 Université de Paris
Sensibilité et Spécificité
c Sensibilité = capacité à diagnostiquer les malades parmi les malades
38 Université de Paris
Un exemple
c Cettematrice de confusion donne
p = précision de 100% et
rappel r = 1%
39 Université de Paris
Courbe ROC
c sur l’axe Y
: sensibilité = Se(s)
c sur l’axe X : 1 - spécificité = 1 - Sp(s)
c AUC = 0,5 ⇒ modèle pas meilleur qu'une notation aléatoire 40 Université de Paris 40
Metrics
Given a set of data points {x(1), ..., x(m)}, where each x(i) has n features, associated to a set of outcomes {y(1), ..., y(m)}, we want to assess a given classifier that learns how to predict y from x.
Classification
In a context of a binary classification, here are the main metrics that are important to track to assess the performance of the model.
❒ Confusion matrix – The confusion matrix is used to have a more complete picture when assessing the performance of a model. It is defined as follows:
Predicted class
+–
❒ ROC – The receiver operating curve, also noted ROC, is the plot of TPR versus FPR by varying the threshold. These metrics are are summed up in the table below:
Metric Formula Equivalent
❒ AUC – The area under the receiving operating curve, also noted AUC or AUROC, is the area below the ROC as shown in the following figure:
Actual class
TP FN
False
True Positives
Negatives
Type II error
FP TN
False
True Negatives
Positives
Type I error
–
Regression
❒ Basic metrics – Given a regression model f, the following metrics are commonly used to assess the performance of the model:
Total sum of squares Explained sum of squares Residual sum of squares
Xm Xm Xm
2 2
(yi − y) (f(xi) − y) (yi − f(xi))2
SStot = SSreg = SSres =
i=1 i=1 i=1
❒ Main metrics – The following metrics are commonly used to assess the performance of classification models:
Metric Formula Interpretation
❒ Coefficient of determination – The coefficient of determination, often noted R2 or r2, provides a measure of how well the observed outcomes are replicated by the model and is defined as follows:
R2 = 1 −SSres
S
St
ot
regression models, by taking into account the number of variables n that they take into consid
❒ Main metrics – The following metrics are commonly used to assess the performance of eration:
where L is the likelihood and bσ2is an estimate of the variance associated with each response.
Model selection
❒ Vocabulary – When selecting a model, we distinguish 3 different parts of the data that we have as follows:
Training set Validation set Testing set
Once the model has been chosen, it is trained on the entire dataset and tested on the unseen test set. These are represented in the figure below:
❒ Cross-validation – Cross-validation, also noted CV, is a method that is used to select a model that does not rely too much on the initial training set. The different types are summed up in the table below:
k-fold Leave-p-out
The most commonly used method is called k-fold cross-validation and splits the training data into k folds to validate the model on one fold while training the model on the k − 1 other folds, all of this k times. The error
is then averaged over the k folds and is named cross-validation error.
❒ Regularization – The regularization procedure aims at avoiding the model to overfit the data and thus deals with high variance issues. The following table sums up the different types of commonly used
regularization techniques:
LASSO Ridge Elastic Net
hi
❒ Model selection – Train model on training set, then evaluate on the development set, then pick best performance model on the development set, and retrain all of that model on the whole training set.
Diagnostics
❒ Bias – The bias of a model is the difference between the expected prediction and the correct model that we try to predict for given data points.
❒ Variance – The variance of a model is the variability of the model prediction for given data points.
❒ Bias/variance tradeoff – The simpler the model, the higher the bias, and the more complex the model, the higher the variance.
Underfitting Just right Overfitting
Regression
Classification