DOC Update notebook style for plot_bayesian_ridge_curvefit
@@ -28,18 +28,16 @@ It can be concluded that the model with larger L is more likely.
# Author: Yoshihiro Uchida <nimbus1after2a1sun7shower@gmail.com>
+# %%
+# Generate sinusoidal data with noise
+# -----------------------------------
import numpy as np
-import matplotlib.pyplot as plt
-
-from sklearn.linear_model import BayesianRidge
def func(x):
return np.sin(2 * np.pi * x)
-# #############################################################################
-# Generate sinusoidal data with noise
size = 25
rng = np.random.RandomState(1234)
x_train = rng.uniform(0.0, 1.0, size)
@@ -47,15 +45,21 @@ y_train = func(x_train) + rng.normal(scale=0.1, size=size)
x_test = np.linspace(0.0, 1.0, 100)
-# #############################################################################
+# %%
# Fit by cubic polynomial
+# -----------------------
+from sklearn.linear_model import BayesianRidge
+
n_order = 3
X_train = np.vander(x_train, n_order + 1, increasing=True)
X_test = np.vander(x_test, n_order + 1, increasing=True)
+reg = BayesianRidge(tol=1e-6, fit_intercept=False, compute_score=True)
-# #############################################################################
+# %%
# Plot the true and predicted curves with log marginal likelihood (L)
-reg = BayesianRidge(tol=1e-6, fit_intercept=False, compute_score=True)
+# -------------------------------------------------------------------
+import matplotlib.pyplot as plt
+
fig, axes = plt.subplots(1, 2, figsize=(8, 4))
for i, ax in enumerate(axes):
# Bayesian ridge regression with different initial value pairs
