Skip to content

Commit 98eea8b

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 67a85b8ed842612d59187e5fdc81a8b86eb50afd
1 parent cddf2ee commit 98eea8b

File tree

943 files changed

+3047
-2799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

943 files changed

+3047
-2799
lines changed
2.23 KB
Binary file not shown.
2.15 KB
Binary file not shown.

dev/_downloads/plot_ard.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
{
1717
"source": [
18-
"\n==================================================\nAutomatic Relevance Determination Regression (ARD)\n==================================================\n\nFit regression model with Bayesian Ridge Regression.\n\nSee `bayesian_ridge_regression` for more information on the regressor.\n\nCompared to the OLS (ordinary least squares) estimator, the coefficient\nweights are slightly shifted toward zeros, which stabilises them.\n\nThe histogram of the estimated weights is very peaked, as a sparsity-inducing\nprior is implied on the weights.\n\nThe estimation of the model is done by iteratively maximizing the\nmarginal log-likelihood of the observations.\n\n"
18+
"\n==================================================\nAutomatic Relevance Determination Regression (ARD)\n==================================================\n\nFit regression model with Bayesian Ridge Regression.\n\nSee `bayesian_ridge_regression` for more information on the regressor.\n\nCompared to the OLS (ordinary least squares) estimator, the coefficient\nweights are slightly shifted toward zeros, which stabilises them.\n\nThe histogram of the estimated weights is very peaked, as a sparsity-inducing\nprior is implied on the weights.\n\nThe estimation of the model is done by iteratively maximizing the\nmarginal log-likelihood of the observations.\n\nWe also plot predictions and uncertainties for ARD\nfor one dimensional regression using polynomial feature expansion.\nNote the uncertainty starts going up on the right side of the plot.\nThis is because these test samples are outside of the range of the training\nsamples.\n\n"
1919
],
2020
"cell_type": "markdown",
2121
"metadata": {}
@@ -69,7 +69,7 @@
6969
},
7070
{
7171
"source": [
72-
"Plot the true weights, the estimated weights and the histogram of the\nweights\n\n"
72+
"Plot the true weights, the estimated weights, the histogram of the\nweights, and predictions with standard deviations\n\n"
7373
],
7474
"cell_type": "markdown",
7575
"metadata": {}
@@ -78,7 +78,7 @@
7878
"execution_count": null,
7979
"cell_type": "code",
8080
"source": [
81-
"plt.figure(figsize=(6, 5))\nplt.title(\"Weights of the model\")\nplt.plot(clf.coef_, color='darkblue', linestyle='-', linewidth=2,\n label=\"ARD estimate\")\nplt.plot(ols.coef_, color='yellowgreen', linestyle=':', linewidth=2,\n label=\"OLS estimate\")\nplt.plot(w, color='orange', linestyle='-', linewidth=2, label=\"Ground truth\")\nplt.xlabel(\"Features\")\nplt.ylabel(\"Values of the weights\")\nplt.legend(loc=1)\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Histogram of the weights\")\nplt.hist(clf.coef_, bins=n_features, color='navy', log=True)\nplt.scatter(clf.coef_[relevant_features], 5 * np.ones(len(relevant_features)),\n color='gold', marker='o', label=\"Relevant features\")\nplt.ylabel(\"Features\")\nplt.xlabel(\"Values of the weights\")\nplt.legend(loc=1)\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Marginal log-likelihood\")\nplt.plot(clf.scores_, color='navy', linewidth=2)\nplt.ylabel(\"Score\")\nplt.xlabel(\"Iterations\")\nplt.show()"
81+
"plt.figure(figsize=(6, 5))\nplt.title(\"Weights of the model\")\nplt.plot(clf.coef_, color='darkblue', linestyle='-', linewidth=2,\n label=\"ARD estimate\")\nplt.plot(ols.coef_, color='yellowgreen', linestyle=':', linewidth=2,\n label=\"OLS estimate\")\nplt.plot(w, color='orange', linestyle='-', linewidth=2, label=\"Ground truth\")\nplt.xlabel(\"Features\")\nplt.ylabel(\"Values of the weights\")\nplt.legend(loc=1)\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Histogram of the weights\")\nplt.hist(clf.coef_, bins=n_features, color='navy', log=True)\nplt.scatter(clf.coef_[relevant_features], 5 * np.ones(len(relevant_features)),\n color='gold', marker='o', label=\"Relevant features\")\nplt.ylabel(\"Features\")\nplt.xlabel(\"Values of the weights\")\nplt.legend(loc=1)\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Marginal log-likelihood\")\nplt.plot(clf.scores_, color='navy', linewidth=2)\nplt.ylabel(\"Score\")\nplt.xlabel(\"Iterations\")\n\n\n# Plotting some predictions for polynomial regression\ndef f(x, noise_amount):\n y = np.sqrt(x) * np.sin(x)\n noise = np.random.normal(0, 1, len(x))\n return y + noise_amount * noise\n\n\ndegree = 10\nX = np.linspace(0, 10, 100)\ny = f(X, noise_amount=1)\nclf_poly = ARDRegression(threshold_lambda=1e5)\nclf_poly.fit(np.vander(X, degree), y)\n\nX_plot = np.linspace(0, 11, 25)\ny_plot = f(X_plot, noise_amount=0)\ny_mean, y_std = clf_poly.predict(np.vander(X_plot, degree), return_std=True)\nplt.figure(figsize=(6, 5))\nplt.errorbar(X_plot, y_mean, y_std, color='navy',\n label=\"Polynomial ARD\", linewidth=2)\nplt.plot(X_plot, y_plot, color='gold', linewidth=2,\n label=\"Ground Truth\")\nplt.ylabel(\"Output y\")\nplt.xlabel(\"Feature X\")\nplt.legend(loc=\"lower left\")\nplt.show()"
8282
],
8383
"outputs": [],
8484
"metadata": {

dev/_downloads/plot_ard.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
1616
The estimation of the model is done by iteratively maximizing the
1717
marginal log-likelihood of the observations.
18+
19+
We also plot predictions and uncertainties for ARD
20+
for one dimensional regression using polynomial feature expansion.
21+
Note the uncertainty starts going up on the right side of the plot.
22+
This is because these test samples are outside of the range of the training
23+
samples.
1824
"""
1925
print(__doc__)
2026

@@ -54,8 +60,8 @@
5460
ols.fit(X, y)
5561

5662
###############################################################################
57-
# Plot the true weights, the estimated weights and the histogram of the
58-
# weights
63+
# Plot the true weights, the estimated weights, the histogram of the
64+
# weights, and predictions with standard deviations
5965
plt.figure(figsize=(6, 5))
6066
plt.title("Weights of the model")
6167
plt.plot(clf.coef_, color='darkblue', linestyle='-', linewidth=2,
@@ -81,4 +87,30 @@
8187
plt.plot(clf.scores_, color='navy', linewidth=2)
8288
plt.ylabel("Score")
8389
plt.xlabel("Iterations")
90+
91+
92+
# Plotting some predictions for polynomial regression
93+
def f(x, noise_amount):
94+
y = np.sqrt(x) * np.sin(x)
95+
noise = np.random.normal(0, 1, len(x))
96+
return y + noise_amount * noise
97+
98+
99+
degree = 10
100+
X = np.linspace(0, 10, 100)
101+
y = f(X, noise_amount=1)
102+
clf_poly = ARDRegression(threshold_lambda=1e5)
103+
clf_poly.fit(np.vander(X, degree), y)
104+
105+
X_plot = np.linspace(0, 11, 25)
106+
y_plot = f(X_plot, noise_amount=0)
107+
y_mean, y_std = clf_poly.predict(np.vander(X_plot, degree), return_std=True)
108+
plt.figure(figsize=(6, 5))
109+
plt.errorbar(X_plot, y_mean, y_std, color='navy',
110+
label="Polynomial ARD", linewidth=2)
111+
plt.plot(X_plot, y_plot, color='gold', linewidth=2,
112+
label="Ground Truth")
113+
plt.ylabel("Output y")
114+
plt.xlabel("Feature X")
115+
plt.legend(loc="lower left")
84116
plt.show()

dev/_downloads/plot_bayesian_ridge.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
{
1717
"source": [
18-
"\n# Bayesian Ridge Regression\n\n\nComputes a Bayesian Ridge Regression on a synthetic dataset.\n\nSee `bayesian_ridge_regression` for more information on the regressor.\n\nCompared to the OLS (ordinary least squares) estimator, the coefficient\nweights are slightly shifted toward zeros, which stabilises them.\n\nAs the prior on the weights is a Gaussian prior, the histogram of the\nestimated weights is Gaussian.\n\nThe estimation of the model is done by iteratively maximizing the\nmarginal log-likelihood of the observations.\n\n"
18+
"\n# Bayesian Ridge Regression\n\n\nComputes a Bayesian Ridge Regression on a synthetic dataset.\n\nSee `bayesian_ridge_regression` for more information on the regressor.\n\nCompared to the OLS (ordinary least squares) estimator, the coefficient\nweights are slightly shifted toward zeros, which stabilises them.\n\nAs the prior on the weights is a Gaussian prior, the histogram of the\nestimated weights is Gaussian.\n\nThe estimation of the model is done by iteratively maximizing the\nmarginal log-likelihood of the observations.\n\nWe also plot predictions and uncertainties for Bayesian Ridge Regression\nfor one dimensional regression using polynomial feature expansion.\nNote the uncertainty starts going up on the right side of the plot.\nThis is because these test samples are outside of the range of the training\nsamples.\n\n"
1919
],
2020
"cell_type": "markdown",
2121
"metadata": {}
@@ -69,7 +69,7 @@
6969
},
7070
{
7171
"source": [
72-
"Plot true weights, estimated weights and histogram of the weights\n\n"
72+
"Plot true weights, estimated weights, histogram of the weights, and\npredictions with standard deviations\n\n"
7373
],
7474
"cell_type": "markdown",
7575
"metadata": {}
@@ -78,7 +78,7 @@
7878
"execution_count": null,
7979
"cell_type": "code",
8080
"source": [
81-
"lw = 2\nplt.figure(figsize=(6, 5))\nplt.title(\"Weights of the model\")\nplt.plot(clf.coef_, color='lightgreen', linewidth=lw,\n label=\"Bayesian Ridge estimate\")\nplt.plot(w, color='gold', linewidth=lw, label=\"Ground truth\")\nplt.plot(ols.coef_, color='navy', linestyle='--', label=\"OLS estimate\")\nplt.xlabel(\"Features\")\nplt.ylabel(\"Values of the weights\")\nplt.legend(loc=\"best\", prop=dict(size=12))\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Histogram of the weights\")\nplt.hist(clf.coef_, bins=n_features, color='gold', log=True)\nplt.scatter(clf.coef_[relevant_features], 5 * np.ones(len(relevant_features)),\n color='navy', label=\"Relevant features\")\nplt.ylabel(\"Features\")\nplt.xlabel(\"Values of the weights\")\nplt.legend(loc=\"upper left\")\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Marginal log-likelihood\")\nplt.plot(clf.scores_, color='navy', linewidth=lw)\nplt.ylabel(\"Score\")\nplt.xlabel(\"Iterations\")\nplt.show()"
81+
"lw = 2\nplt.figure(figsize=(6, 5))\nplt.title(\"Weights of the model\")\nplt.plot(clf.coef_, color='lightgreen', linewidth=lw,\n label=\"Bayesian Ridge estimate\")\nplt.plot(w, color='gold', linewidth=lw, label=\"Ground truth\")\nplt.plot(ols.coef_, color='navy', linestyle='--', label=\"OLS estimate\")\nplt.xlabel(\"Features\")\nplt.ylabel(\"Values of the weights\")\nplt.legend(loc=\"best\", prop=dict(size=12))\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Histogram of the weights\")\nplt.hist(clf.coef_, bins=n_features, color='gold', log=True)\nplt.scatter(clf.coef_[relevant_features], 5 * np.ones(len(relevant_features)),\n color='navy', label=\"Relevant features\")\nplt.ylabel(\"Features\")\nplt.xlabel(\"Values of the weights\")\nplt.legend(loc=\"upper left\")\n\nplt.figure(figsize=(6, 5))\nplt.title(\"Marginal log-likelihood\")\nplt.plot(clf.scores_, color='navy', linewidth=lw)\nplt.ylabel(\"Score\")\nplt.xlabel(\"Iterations\")\n\n\n# Plotting some predictions for polynomial regression\ndef f(x, noise_amount):\n y = np.sqrt(x) * np.sin(x)\n noise = np.random.normal(0, 1, len(x))\n return y + noise_amount * noise\n\n\ndegree = 10\nX = np.linspace(0, 10, 100)\ny = f(X, noise_amount=0.1)\nclf_poly = BayesianRidge()\nclf_poly.fit(np.vander(X, degree), y)\n\nX_plot = np.linspace(0, 11, 25)\ny_plot = f(X_plot, noise_amount=0)\ny_mean, y_std = clf_poly.predict(np.vander(X_plot, degree), return_std=True)\nplt.figure(figsize=(6, 5))\nplt.errorbar(X_plot, y_mean, y_std, color='navy',\n label=\"Polynomial Bayesian Ridge Regression\", linewidth=lw)\nplt.plot(X_plot, y_plot, color='gold', linewidth=lw,\n label=\"Ground Truth\")\nplt.ylabel(\"Output y\")\nplt.xlabel(\"Feature X\")\nplt.legend(loc=\"lower left\")\nplt.show()"
8282
],
8383
"outputs": [],
8484
"metadata": {

dev/_downloads/plot_bayesian_ridge.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
1616
The estimation of the model is done by iteratively maximizing the
1717
marginal log-likelihood of the observations.
18+
19+
We also plot predictions and uncertainties for Bayesian Ridge Regression
20+
for one dimensional regression using polynomial feature expansion.
21+
Note the uncertainty starts going up on the right side of the plot.
22+
This is because these test samples are outside of the range of the training
23+
samples.
1824
"""
1925
print(__doc__)
2026

@@ -51,7 +57,8 @@
5157
ols.fit(X, y)
5258

5359
###############################################################################
54-
# Plot true weights, estimated weights and histogram of the weights
60+
# Plot true weights, estimated weights, histogram of the weights, and
61+
# predictions with standard deviations
5562
lw = 2
5663
plt.figure(figsize=(6, 5))
5764
plt.title("Weights of the model")
@@ -77,4 +84,30 @@
7784
plt.plot(clf.scores_, color='navy', linewidth=lw)
7885
plt.ylabel("Score")
7986
plt.xlabel("Iterations")
87+
88+
89+
# Plotting some predictions for polynomial regression
90+
def f(x, noise_amount):
91+
y = np.sqrt(x) * np.sin(x)
92+
noise = np.random.normal(0, 1, len(x))
93+
return y + noise_amount * noise
94+
95+
96+
degree = 10
97+
X = np.linspace(0, 10, 100)
98+
y = f(X, noise_amount=0.1)
99+
clf_poly = BayesianRidge()
100+
clf_poly.fit(np.vander(X, degree), y)
101+
102+
X_plot = np.linspace(0, 11, 25)
103+
y_plot = f(X_plot, noise_amount=0)
104+
y_mean, y_std = clf_poly.predict(np.vander(X_plot, degree), return_std=True)
105+
plt.figure(figsize=(6, 5))
106+
plt.errorbar(X_plot, y_mean, y_std, color='navy',
107+
label="Polynomial Bayesian Ridge Regression", linewidth=lw)
108+
plt.plot(X_plot, y_plot, color='gold', linewidth=lw,
109+
label="Ground Truth")
110+
plt.ylabel("Output y")
111+
plt.xlabel("Feature X")
112+
plt.legend(loc="lower left")
80113
plt.show()

dev/_downloads/scikit-learn-docs.pdf

76.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)