Commit 0affb9fb authored by Rémy Huet's avatar Rémy Huet 💻
Browse files

Début TP2

parent d006d330
......@@ -9,6 +9,9 @@ numpy = "*"
scipy = "*"
matplotlib = "*"
ipywidgets = "*"
pandas = "*"
seaborn = "*"
scikit-learn = "*"
[dev-packages]
......
This diff is collapsed.
%% Cell type:code id: tags:
```
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
```
%% Cell type:markdown id: tags:
# Bayesian linear regression
## Synthetic data
%% Cell type:code id: tags:
```
# Defined model for the exercise
def model(x):
f = 0.2 + x**2
y = f + np.random.normal(loc=0.0, scale=1.0, size=x.shape)
return y
# training data
Xtr = np.array([[-1,0,1,2,3]]).T
ytr = model(Xtr)
# test data
Xte = np.array([[-2, 5]]).T
Yte = model(Xte)
# data for plotting
Xpl = np.atleast_2d(np.linspace(-5,5,100)).T
plt.figure(figsize=(5,5))
plt.plot(Xtr, ytr, 'bo', label='train data')
plt.plot(Xte, Yte, 'g+', label='test data')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()
```
%% Cell type:markdown id: tags:
## Bayesian (Gaussian) linear regression
### Programming
We want to program a function to make predictions given:
- A set Xtr of training instances (X matrix)
- The associated values ytr (y vector)
- A noise covariance matrix $\Sigma n$
- A prior matrix $\Sigma p$
- A set of instances Xpr for wich predictions must be made.
%% Cell type:code id: tags:
```
def predGLR(Xpr, Xtr, ytr, Sign, Sigp):
Xtr = np.concatenate([np.ones(Xtr.shape), Xtr], axis=1)
Xpr = np.concatenate([np.ones(Xpr.shape), Xpr], axis=1)
```
%% Cell type:markdown id: tags:
# Gaussian process regression
%% Cell type:code id: tags:
```
from sklearn.gaussian_process import GaussianProcessRegressor as GPR
from sklearn.gaussian_process.kernels import DotProduct, WhiteKernel
```
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment