8000 DOC Update notebook style for plot_bayesian_ridge_curvefit (#22916) · scikit-learn/scikit-learn@24ef388 · GitHub
[go: up one dir, main page]

Skip to content

Commit 24ef388

Browse files
2357juanJuan Gomez
and
Juan Gomez
authored
DOC Update notebook style for plot_bayesian_ridge_curvefit (#22916)
Co-authored-by: Juan Gomez <jgomez75@gatech.edu>
1 parent 7931262 commit 24ef388

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

examples/linear_model/plot_bayesian_ridge_curvefit.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,38 @@
2828

2929
# Author: Yoshihiro Uchida <nimbus1after2a1sun7shower@gmail.com>
3030

31+
# %%
32+
# Generate sinusoidal data with noise
33+
# -----------------------------------
3134
import numpy as np
32-
import matplotlib.pyplot as plt
33-
34-
from sklearn.linear_model import BayesianRidge
3535

3636

3737
def func(x):
3838
return np.sin(2 * np.pi * x)
3939

4040

41-
# #############################################################################
42-
# Generate sinusoidal data with noise
4341
size = 25
4442
rng = np.random.RandomState(1234)
4543
x_train = rng.uniform(0.0, 1.0, size)
4644
y_train = func(x_train) + rng.normal(scale=0.1, size=size)
4745
x_test = np.linspace(0.0, 1.0, 100)
4846

4947

50-
# #############################################################################
48+
# %%
5149
# Fit by cubic polynomial
50+
# -----------------------
51+
from sklearn.linear_model import BayesianRidge
52+
5253
n_order = 3
5354
X_train = np.vander(x_train, n_order + 1, increasing=True)
5455
X_test = np.vander(x_test, n_order + 1, increasing=True)
56+
reg = BayesianRidge(tol=1e-6, fit_intercept=False, compute_score=True)
5557

56-
# #############################################################################
58+
# %%
5759
# Plot the true and predicted curves with log marginal likelihood (L)
58-
reg = BayesianRidge(tol=1e-6, fit_intercept=False, compute_score=True)
60+
# -------------------------------------------------------------------
61+
import matplotlib.pyplot as plt
62+
5963
fig, axes = plt.subplots(1, 2, figsize=(8, 4))
6064
for i, ax in enumerate(axes):
6165
# Bayesian ridge regression with different initial value pairs

0 commit comments

Comments
 (0)
0