add introduction to kernel ridge regression
This commit is contained in:
parent
fcea9a12ab
commit
ddb4a021f3
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@
|
||||
15_loocv.pdf
|
||||
16_biais_variance_estimateur.pdf
|
||||
17_biais_variance_ridge.pdf
|
||||
18_kernel_ridge_regression.pdf
|
70
18_kernel_ridge_regression.Rmd
Normal file
70
18_kernel_ridge_regression.Rmd
Normal file
@ -0,0 +1,70 @@
|
||||
---
|
||||
title: "18 Kernel ridge regression"
|
||||
output:
|
||||
bookdown::pdf_document2:
|
||||
number_section: yes
|
||||
includes:
|
||||
in_header: preamble.tex
|
||||
toc: false
|
||||
classoption: fleqn
|
||||
---
|
||||
|
||||
# Noyau gaussien
|
||||
|
||||
Soit un jeu de données :
|
||||
$$
|
||||
(\mathbf{x_i},y_i) \quad \text{avec} \quad i=1,\dots,n \quad ; \quad y_i \in \mathbb{R} \quad ; \quad \mathbf{x_i} \in \mathbb{R}^d
|
||||
$$
|
||||
|
||||
Nous appelons \emph{noyau} une mesure de similarité entre points :
|
||||
$$
|
||||
k: \mathbb{R}^d \times \mathbb{R}^d \rightarrow \mathbb{R}
|
||||
$$
|
||||
|
||||
La similarité peut, par exemple, être représentée par une fonction gaussienne :
|
||||
$$
|
||||
k(\mathbf{x_j},\mathbf{x_i}) = exp\left(-\frac{1}{\sigma^2}\|\mathbf{x_j}-\mathbf{x_i}\|^2\right)
|
||||
$$
|
||||
Avec $\|\mathbf{x_j}-\mathbf{x_i}\|$ la distance euclidienne entre observations. Nous traçons ci-dessous la forme de cette décroissance exponentielle. Lorsque la distance entre $\mathbf{x_j}$ et $\mathbf{x_i}$ est nulle, la similarité est maximale et vaut $1$.
|
||||
|
||||
```{r}
|
||||
d <- seq(from=0, to=5, by=0.1)
|
||||
k <- function(sigma,d){exp(-(1/sigma^2)*d^2)}
|
||||
plot(x=d, y=k(1,d), type="l")
|
||||
```
|
||||
|
||||
Nous proposons ensuite de représenter la relation entre les observations et la cible par une combinaison linéaire des similarités d'une nouvelle observation $\mathbf{x}$ avec chaque observation du jeu d'entraînement :
|
||||
$$
|
||||
f(\mathbf{x}) = \sum_{i=1}^{n} \alpha_i k(\mathbf{x},\mathbf{x_i})
|
||||
$$
|
||||
Plus $\mathbf{x}$ est proche de $\mathbf{x_i}$, plus $\mathbf{x_i}$ pèse dans le calcul de la valeur prédite pour $\mathbf{x}$.
|
||||
Chaque $k(\cdot,\mathbf{x_i})$ est une fonction gaussienne et $f$ est une superposition de fonctions gaussiennes.
|
||||
Nous proposons une illustration d'une telle superposition.
|
||||
|
||||
```{r}
|
||||
set.seed(1123)
|
||||
npts <- 8
|
||||
xi <- runif(npts, min=0, max=5)
|
||||
ci <- rnorm(npts)
|
||||
xs <- seq(from=0, to=5, by=0.1)
|
||||
fi <- function(ci,xi) function(x) ci * exp(-(x-xi)^2)
|
||||
call_f <- function(f,...) f(...)
|
||||
m <- t(matrix(unlist(lapply(Map(fi,ci,xi), call_f, xs)), nrow=npts, byrow=TRUE))
|
||||
f <- rowSums(m)
|
||||
plot(xs, f, type="l", lty="solid", ylim=range(cbind(f,m)))
|
||||
matplot(xs, m, type="l", lty="dotted", col=1, add=TRUE)
|
||||
points(x=xi, y=rep(0,npts))
|
||||
```
|
||||
|
||||
Cette approche est qualifiée de \emph{non paramétrique} car elle s'adapte aux données au lieu de chercher à adpater les paramètres d'une forme fonctionnelle fixée a priori comme nous le faisions auparavant dans le cas de la régression régularisée.
|
||||
|
||||
# Régression ridge avec noyau
|
||||
|
||||
Nous montrons que l'approche non paramétrique introduite ci-dessus peut se présenter sous la forme d'une régression ridge après transformation des variables $\mathbf{x_i}$ par une fonction $\phi$.
|
||||
$$
|
||||
\begin{aligned}
|
||||
\mathbf{X} &\in \mathbb{R}^{n\times d} \\
|
||||
\hat{\boldsymbol\beta} &= (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y} \quad \text{Régression normale} \\
|
||||
\hat{\boldsymbol\beta}_\lambda &= \left(\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I}_d\right)^{-1}\mathbf{X}^T\mathbf{y} \quad \text{Régression ridge} \\
|
||||
\end{aligned}
|
||||
$$
|
Loading…
Reference in New Issue
Block a user