Skip to content

Commit 2379562

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 4f70d8585ba4107a190ccadae7f20adbc4e47e46
1 parent 1533553 commit 2379562

File tree

1,227 files changed

+4589
-4433
lines changed

Some content is hidden

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

1,227 files changed

+4589
-4433
lines changed
Binary file not shown.
Binary file not shown.

dev/_downloads/892d774326b523935a603b8700193195/plot_ard.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from sklearn.linear_model import ARDRegression, LinearRegression
3232

33-
# #############################################################################
33+
# %%
3434
# Generating simulated data with Gaussian weights
3535

3636
# Parameters of the example
@@ -51,15 +51,15 @@
5151
# Create the target
5252
y = np.dot(X, w) + noise
5353

54-
# #############################################################################
54+
# %%
5555
# Fit the ARD Regression
5656
clf = ARDRegression(compute_score=True)
5757
clf.fit(X, y)
5858

5959
ols = LinearRegression()
6060
ols.fit(X, y)
6161

62-
# #############################################################################
62+
# %%
6363
# Plot the true weights, the estimated weights, the histogram of the
6464
# weights, and predictions with standard deviations
6565
plt.figure(figsize=(6, 5))

dev/_downloads/c5d41d4d7d1dab3e49804c2e2c4222e8/plot_ard.ipynb

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,61 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import stats\n\nfrom sklearn.linear_model import ARDRegression, LinearRegression\n\n# #############################################################################\n# Generating simulated data with Gaussian weights\n\n# Parameters of the example\nnp.random.seed(0)\nn_samples, n_features = 100, 100\n# Create Gaussian data\nX = np.random.randn(n_samples, n_features)\n# Create weights with a precision lambda_ of 4.\nlambda_ = 4.0\nw = np.zeros(n_features)\n# Only keep 10 weights of interest\nrelevant_features = np.random.randint(0, n_features, 10)\nfor i in relevant_features:\n w[i] = stats.norm.rvs(loc=0, scale=1.0 / np.sqrt(lambda_))\n# Create noise with a precision alpha of 50.\nalpha_ = 50.0\nnoise = stats.norm.rvs(loc=0, scale=1.0 / np.sqrt(alpha_), size=n_samples)\n# Create the target\ny = np.dot(X, w) + noise\n\n# #############################################################################\n# Fit the ARD Regression\nclf = ARDRegression(compute_score=True)\nclf.fit(X, y)\n\nols = LinearRegression()\nols.fit(X, y)\n\n# #############################################################################\n# Plot the true weights, the estimated weights, the histogram of the\n# weights, and predictions with standard deviations\nplt.figure(figsize=(6, 5))\nplt.title(\"Weights of the model\")\nplt.plot(clf.coef_, color=\"darkblue\", linestyle=\"-\", linewidth=2, label=\"ARD estimate\")\nplt.plot(\n ols.coef_, color=\"yellowgreen\", linestyle=\":\", linewidth=2, label=\"OLS estimate\"\n)\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(\n clf.coef_[relevant_features],\n np.full(len(relevant_features), 5.0),\n color=\"gold\",\n marker=\"o\",\n label=\"Relevant features\",\n)\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\", label=\"Polynomial ARD\", linewidth=2)\nplt.plot(X_plot, y_plot, color=\"gold\", linewidth=2, label=\"Ground Truth\")\nplt.ylabel(\"Output y\")\nplt.xlabel(\"Feature X\")\nplt.legend(loc=\"lower left\")\nplt.show()"
29+
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import stats\n\nfrom sklearn.linear_model import ARDRegression, LinearRegression"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"Generating simulated data with Gaussian weights\n\n"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": false
44+
},
45+
"outputs": [],
46+
"source": [
47+
"# Parameters of the example\nnp.random.seed(0)\nn_samples, n_features = 100, 100\n# Create Gaussian data\nX = np.random.randn(n_samples, n_features)\n# Create weights with a precision lambda_ of 4.\nlambda_ = 4.0\nw = np.zeros(n_features)\n# Only keep 10 weights of interest\nrelevant_features = np.random.randint(0, n_features, 10)\nfor i in relevant_features:\n w[i] = stats.norm.rvs(loc=0, scale=1.0 / np.sqrt(lambda_))\n# Create noise with a precision alpha of 50.\nalpha_ = 50.0\nnoise = stats.norm.rvs(loc=0, scale=1.0 / np.sqrt(alpha_), size=n_samples)\n# Create the target\ny = np.dot(X, w) + noise"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"Fit the ARD Regression\n\n"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {
61+
"collapsed": false
62+
},
63+
"outputs": [],
64+
"source": [
65+
"clf = ARDRegression(compute_score=True)\nclf.fit(X, y)\n\nols = LinearRegression()\nols.fit(X, y)"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"Plot the true weights, the estimated weights, the histogram of the\nweights, and predictions with standard deviations\n\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {
79+
"collapsed": false
80+
},
81+
"outputs": [],
82+
"source": [
83+
"plt.figure(figsize=(6, 5))\nplt.title(\"Weights of the model\")\nplt.plot(clf.coef_, color=\"darkblue\", linestyle=\"-\", linewidth=2, label=\"ARD estimate\")\nplt.plot(\n ols.coef_, color=\"yellowgreen\", linestyle=\":\", linewidth=2, label=\"OLS estimate\"\n)\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(\n clf.coef_[relevant_features],\n np.full(len(relevant_features), 5.0),\n color=\"gold\",\n marker=\"o\",\n label=\"Relevant features\",\n)\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\", label=\"Polynomial ARD\", linewidth=2)\nplt.plot(X_plot, y_plot, color=\"gold\", linewidth=2, label=\"Ground Truth\")\nplt.ylabel(\"Output y\")\nplt.xlabel(\"Feature X\")\nplt.legend(loc=\"lower left\")\nplt.show()"
3084
]
3185
}
3286
],

dev/_downloads/scikit-learn-docs.zip

4.34 KB
Binary file not shown.
-86 Bytes
390 Bytes
-104 Bytes
-18 Bytes
-6 Bytes
-41 Bytes
-26 Bytes
-114 Bytes
-560 Bytes
-159 Bytes
-82 Bytes
-12 Bytes
47 Bytes
57 Bytes
168 Bytes
-63 Bytes
116 Bytes
-26 Bytes
-108 Bytes
136 Bytes
131 Bytes
-351 Bytes
-38 Bytes
-828 Bytes
-342 Bytes
375 Bytes
-22 Bytes
0 Bytes

dev/_sources/auto_examples/applications/plot_cyclical_feature_engineering.rst.txt

Lines changed: 1 addition & 1 deletion

dev/_sources/auto_examples/applications/plot_digits_denoising.rst.txt

Lines changed: 1 addition & 1 deletion

dev/_sources/auto_examples/applications/plot_face_recognition.rst.txt

Lines changed: 5 additions & 5 deletions

dev/_sources/auto_examples/applications/plot_model_complexity_influence.rst.txt

Lines changed: 14 additions & 14 deletions

0 commit comments

Comments
 (0)