Académique Documents
Professionnel Documents
Culture Documents
Regressions
Sources de données
www.kaggle.com
http://archive.ics.uci.edu/ml/
Jouer avec les données... C’est un métier : data scientist.
Hypothèse
relation imprécise entre X et Y
valeur de Y dépend de X et d’un facteur aléatoire E :
Y = f (X , E)
E = résidu = erreur = bruit
Y = f (X , E)
Y
yi
i
X
xi
Y =α+βX +E
Y
yi
ǫi
X
xi
Modélisation : Y = α + βX + E
On dispose d’un ensemble d’observations (xi , yi )
⇒ trouver α? , β ?
Modélisation : Y = α + βX + E
E est une variable aléatoire, {. . . , Ei , . . .} sont des tirages
selon cette loi
Hypothèse (dite du bruit blanc) : E ∼ N (0, σ)
Notations :
Yi = α + βXi + Ei et : E[Yi ] = α + βxi , V [Yi ] = σ 2
On note Yi ∼ N (α + βxi , σ)
Y = α + βX + E E(Y ) = α + βE(X )
Y = α + βX + E E(Y ) = α + βE(X )
Y = α + βX + E E(Y ) = α + βE(X )
E[(Y − E(Y ))(X − E(X ))] = βE[(X − E(X ))2 ] + E[E(X − E(X ))]
Y = α + βX + E E(Y ) = α + βE(X )
E[(Y − E(Y ))(X − E(X ))] = βE[(X − E(X ))2 ] + E[E(X − E(X ))]
Y = α + βX + E E(Y ) = α + βE(X )
cov(X , Y ) cov(X , Y )
β? = α? = E(Y ) − E(X )
σx2 σx2
Y
yi
ǫi
X
xi
cov(X , Y ) cov(X , Y )
β? = α? = E(Y ) − E(X )
σx2 σx2
MAPSI — cours 10 : Regressions 11/35
Conclusion (2)
Ca marche bien...
1.5
1.0
0.5
0.0
0.5
1.0
1.5
0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2
6
1.0
5
0.5
4
0.0 3
2
0.5
1
1.0
0
1.5 1
0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2 0.2 0.0 0.2 0.4 0.6 0.8 1.0 1.2
ln Y = −1 + 0, 5X 2
=⇒ changement de variables : Y 0 = ln Y et X 0 = X 2
=⇒ Y 0 = −1 + 0, 5X 0
Vraisemblance :
1 1
kyi − f (xi )k2 )
Y
L = p(y|x, θ, σ) = √ exp(−
2πσ 2σ 2
i
Approche standard :
Calcul du gradient
Annulation du gradient
Analytique (si possible)
Itérative (sinon)
a11 a12 a13 α b1
∇α,β,γ log L = 0 ⇔ a21 a22 a23 β = b2
a31 a32 a33 γ b3
sklearn
MAPSI — cours 10 : Regressions 17/35
Approche par minimisation du coût
Coût
Approche
e par minimisation par
du coût minimisation du cou
t la vraisemblance
maximisent la vraisemblance
blance
X
xi
Définition de la droite
n
ei2
X
trouver a et b pour lesquels on a : min
a,b
i=1
n
[yi − a − bxi ]2 =⇒ min F (a, b)
X
ou encore : F (a, b) =
a,b
i=1
n
∂F (a, b) X
= (−2)[yi − a − bxi ] = 0 (1)
∂a
i=1
n
∂F (a, b) X
= (−2)xi [yi − a − bxi ] = 0 (2)
∂b
i=1
P
i xi (yi − y) cov (x, y)
=⇒ b = P 2
=
2 sx2
P
i xi − n( i xi )
MAPSI — cours 10 : Regressions 21/35
Coût des moindres carrés (3)
n
∂F (a, b) X
= (−2)[yi − a − bxi ] = 0 (1)
∂a
i=1
n
∂F (a, b) X
= (−2)xi [yi − a − bxi ] = 0 (2)
∂b
i=1
n n n
1X 1X 1X
= (ŷi − y )2 + (ei )2 + 2 ei (ŷi − y)
n n n
i=1 i=1 i=1
n n n
1X 1X 1X
= (ŷi − y )2 + (ei )2 + 2 ei (ŷi − y)
n n n
i=1 i=1 i=1
n
1X
Or ei (ŷi − y) = cov (ei , ŷi ) = cov (ei , a + bxi ) = b cov (ei , xi ) = 0
n
i=1
n n
1X 1X
Donc sy2 = (ŷi − y)2 + (ei )2
n n
i=1 i=1
Y Y
X X
R 2 petit R 2 élevé
x11 x12 · · · x1d y1
X = ...
.
, Y = .. .
∂C X
= 2xij (fw (xi ) − yi )
∂wj
i
∂C
∂w1
∇w C = ... = 2X (X w − Y ) ∈ R
T d
∂C
∂wd
∂C X
= 2xij (fw (xi ) − yi )
∂wj
i
∂C
∂w1
∇w C = ... = 2X (X w − Y ) ∈ R
T d
∂C
∂wd
Résolution :
∇w C = 0 ⇔ X T X w = X T Y
Système d’équations linéaires : X T X ∈ Rd×d , X T Y ∈ Rd×1
40 40
30
30
20
20
10
10
0
0
-10
-10
-20
-20
0 2 4 6 8 10 0 2 4 6 8 10
30
30
20
20
10
10
0
0
-10
-10
-20
-20
0 2 4 6 8 10 0 2 4 6 8 10
Xe = [1, X , X . ∗ X ]
Moindres carrés :
N N
(fθ (xi ) − yi )2
X X
C= ∆(fθ (xi ), yi ) =
i=1 i=1
Algorithme itératif :
1 Initialiser w0
2 En boucle (avec mise à jour du gradient) :
wt+1 = wt − ∇w C
Perceptron
Algorithme de classification binaire des années 60 : toujours
très efficace aujourd’hui
N
X
C= (−yi xi w)+
i=1