Skip to content

Commit dc681db

Browse files
committed
Pushing the docs to dev/ for branch: main, commit fb9f0b95988bf4a9a1e04fa0667daedbec82a3af
1 parent b033c04 commit dc681db

File tree

1,636 files changed

+7062
-8822
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,636 files changed

+7062
-8822
lines changed

dev/.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: 4b570ac32390455c575a82298890bf3d
3+
config: 7c588470fefc9f086d133514a7c5fa6f
44
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"\n# Lasso, Lasso-LARS, and Elastic Net paths\n\nThis example shows how to compute the \"paths\" of coefficients along the Lasso,\nLasso-LARS, and Elastic Net regularization paths. In other words, it shows the\nrelationship between the regularization parameter (alpha) and the coefficients.\n\nLasso and Lasso-LARS impose a sparsity constraint on the coefficients,\nencouraging some of them to be zero. Elastic Net is a generalization of\nLasso that adds an L2 penalty term to the L1 penalty term. This allows for\nsome coefficients to be non-zero while still encouraging sparsity.\n\nLasso and Elastic Net use a coordinate descent method to compute the paths, while\nLasso-LARS uses the LARS algorithm to compute the paths.\n\nThe paths are computed using :func:`~sklearn.linear_model.lasso_path`,\n:func:`~sklearn.linear_model.lars_path`, and :func:`~sklearn.linear_model.enet_path`.\n\nThe results show different comparison plots:\n\n- Compare Lasso and Lasso-LARS\n- Compare Lasso and Elastic Net\n- Compare Lasso with positive Lasso\n- Compare LARS and Positive LARS\n- Compare Elastic Net and positive Elastic Net\n\nEach plot shows how the model coefficients vary as the regularization strength changes,\noffering insight into the behavior of these models\nunder different constraints.\n"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"collapsed": false
15+
},
16+
"outputs": [],
17+
"source": [
18+
"# Authors: The scikit-learn developers\n# SPDX-License-Identifier: BSD-3-Clause\n\nfrom itertools import cycle\n\nimport matplotlib.pyplot as plt\n\nfrom sklearn.datasets import load_diabetes\nfrom sklearn.linear_model import enet_path, lars_path, lasso_path\n\nX, y = load_diabetes(return_X_y=True)\nX /= X.std(axis=0) # Standardize data (easier to set the l1_ratio parameter)\n\n# Compute paths\n\neps = 5e-3 # the smaller it is the longer is the path\n\nprint(\"Computing regularization path using the lasso...\")\nalphas_lasso, coefs_lasso, _ = lasso_path(X, y, eps=eps)\n\nprint(\"Computing regularization path using the positive lasso...\")\nalphas_positive_lasso, coefs_positive_lasso, _ = lasso_path(\n X, y, eps=eps, positive=True\n)\n\nprint(\"Computing regularization path using the LARS...\")\nalphas_lars, _, coefs_lars = lars_path(X, y, method=\"lasso\")\n\nprint(\"Computing regularization path using the positive LARS...\")\nalphas_positive_lars, _, coefs_positive_lars = lars_path(\n X, y, method=\"lasso\", positive=True\n)\n\nprint(\"Computing regularization path using the elastic net...\")\nalphas_enet, coefs_enet, _ = enet_path(X, y, eps=eps, l1_ratio=0.8)\n\nprint(\"Computing regularization path using the positive elastic net...\")\nalphas_positive_enet, coefs_positive_enet, _ = enet_path(\n X, y, eps=eps, l1_ratio=0.8, positive=True\n)\n\n# Display results\n\nplt.figure(1)\ncolors = cycle([\"b\", \"r\", \"g\", \"c\", \"k\"])\nfor coef_lasso, coef_lars, c in zip(coefs_lasso, coefs_lars, colors):\n l1 = plt.semilogx(alphas_lasso, coef_lasso, c=c)\n l2 = plt.semilogx(alphas_lars, coef_lars, linestyle=\"--\", c=c)\n\nplt.xlabel(\"alpha\")\nplt.ylabel(\"coefficients\")\nplt.title(\"Lasso and LARS Paths\")\nplt.legend((l1[-1], l2[-1]), (\"Lasso\", \"LARS\"), loc=\"lower right\")\nplt.axis(\"tight\")\n\nplt.figure(2)\ncolors = cycle([\"b\", \"r\", \"g\", \"c\", \"k\"])\nfor coef_l, coef_e, c in zip(coefs_lasso, coefs_enet, colors):\n l1 = plt.semilogx(alphas_lasso, coef_l, c=c)\n l2 = plt.semilogx(alphas_enet, coef_e, linestyle=\"--\", c=c)\n\nplt.xlabel(\"alpha\")\nplt.ylabel(\"coefficients\")\nplt.title(\"Lasso and Elastic-Net Paths\")\nplt.legend((l1[-1], l2[-1]), (\"Lasso\", \"Elastic-Net\"), loc=\"lower right\")\nplt.axis(\"tight\")\n\n\nplt.figure(3)\nfor coef_l, coef_pl, c in zip(coefs_lasso, coefs_positive_lasso, colors):\n l1 = plt.semilogy(alphas_lasso, coef_l, c=c)\n l2 = plt.semilogy(alphas_positive_lasso, coef_pl, linestyle=\"--\", c=c)\n\nplt.xlabel(\"alpha\")\nplt.ylabel(\"coefficients\")\nplt.title(\"Lasso and positive Lasso\")\nplt.legend((l1[-1], l2[-1]), (\"Lasso\", \"positive Lasso\"), loc=\"lower right\")\nplt.axis(\"tight\")\n\n\nplt.figure(4)\ncolors = cycle([\"b\", \"r\", \"g\", \"c\", \"k\"])\nfor coef_lars, coef_positive_lars, c in zip(coefs_lars, coefs_positive_lars, colors):\n l1 = plt.semilogx(alphas_lars, coef_lars, c=c)\n l2 = plt.semilogx(alphas_positive_lars, coef_positive_lars, linestyle=\"--\", c=c)\n\nplt.xlabel(\"alpha\")\nplt.ylabel(\"coefficients\")\nplt.title(\"LARS and Positive LARS\")\nplt.legend((l1[-1], l2[-1]), (\"LARS\", \"Positive LARS\"), loc=\"lower right\")\nplt.axis(\"tight\")\n\nplt.figure(5)\nfor coef_e, coef_pe, c in zip(coefs_enet, coefs_positive_enet, colors):\n l1 = plt.semilogx(alphas_enet, coef_e, c=c)\n l2 = plt.semilogx(alphas_positive_enet, coef_pe, linestyle=\"--\", c=c)\n\nplt.xlabel(\"alpha\")\nplt.ylabel(\"coefficients\")\nplt.title(\"Elastic-Net and positive Elastic-Net\")\nplt.legend((l1[-1], l2[-1]), (\"Elastic-Net\", \"positive Elastic-Net\"), loc=\"lower right\")\nplt.axis(\"tight\")\nplt.show()"
19+
]
20+
}
21+
],
22+
"metadata": {
23+
"kernelspec": {
24+
"display_name": "Python 3",
25+
"language": "python",
26+
"name": "python3"
27+
},
28+
"language_info": {
29+
"codemirror_mode": {
30+
"name": "ipython",
31+
"version": 3
32+
},
33+
"file_extension": ".py",
34+
"mimetype": "text/x-python",
35+
"name": "python",
36+
"nbconvert_exporter": "python",
37+
"pygments_lexer": "ipython3",
38+
"version": "3.9.20"
39+
}
40+
},
41+
"nbformat": 4,
42+
"nbformat_minor": 0
43+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/1f682002d8b68c290d9d03599368e83d/plot_lasso_coordinate_descent_path.py

Lines changed: 0 additions & 84 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
"""
2+
========================================
3+
Lasso, Lasso-LARS, and Elastic Net paths
4+
========================================
5+
6+
This example shows how to compute the "paths" of coefficients along the Lasso,
7+
Lasso-LARS, and Elastic Net regularization paths. In other words, it shows the
8+
relationship between the regularization parameter (alpha) and the coefficients.
9+
10+
Lasso and Lasso-LARS impose a sparsity constraint on the coefficients,
11+
encouraging some of them to be zero. Elastic Net is a generalization of
12+
Lasso that adds an L2 penalty term to the L1 penalty term. This allows for
13+
some coefficients to be non-zero while still encouraging sparsity.
14+
15+
Lasso and Elastic Net use a coordinate descent method to compute the paths, while
16+
Lasso-LARS uses the LARS algorithm to compute the paths.
17+
18+
The paths are computed using :func:`~sklearn.linear_model.lasso_path`,
19+
:func:`~sklearn.linear_model.lars_path`, and :func:`~sklearn.linear_model.enet_path`.
20+
21+
The results show different comparison plots:
22+
23+
- Compare Lasso and Lasso-LARS
24+
- Compare Lasso and Elastic Net
25+
- Compare Lasso with positive Lasso
26+
- Compare LARS and Positive LARS
27+
- Compare Elastic Net and positive Elastic Net
28+
29+
Each plot shows how the model coefficients vary as the regularization strength changes,
30+
offering insight into the behavior of these models
31+
under different constraints.
32+
"""
33+
34+
# Authors: The scikit-learn developers
35+
# SPDX-License-Identifier: BSD-3-Clause
36+
37+
from itertools import cycle
38+
39+
import matplotlib.pyplot as plt
40+
41+
from sklearn.datasets import load_diabetes
42+
from sklearn.linear_model import enet_path, lars_path, lasso_path
43+
44+
X, y = load_diabetes(return_X_y=True)
45+
X /= X.std(axis=0) # Standardize data (easier to set the l1_ratio parameter)
46+
47+
# Compute paths
48+
49+
eps = 5e-3 # the smaller it is the longer is the path
50+
51+
print("Computing regularization path using the lasso...")
52+
alphas_lasso, coefs_lasso, _ = lasso_path(X, y, eps=eps)
53+
54+
print("Computing regularization path using the positive lasso...")
55+
alphas_positive_lasso, coefs_positive_lasso, _ = lasso_path(
56+
X, y, eps=eps, positive=True
57+
)
58+
59+
print("Computing regularization path using the LARS...")
60+
alphas_lars, _, coefs_lars = lars_path(X, y, method="lasso")
61+
62+
print("Computing regularization path using the positive LARS...")
63+
alphas_positive_lars, _, coefs_positive_lars = lars_path(
64+
X, y, method="lasso", positive=True
65+
)
66+
67+
print("Computing regularization path using the elastic net...")
68+
alphas_enet, coefs_enet, _ = enet_path(X, y, eps=eps, l1_ratio=0.8)
69+
70+
print("Computing regularization path using the positive elastic net...")
71+
alphas_positive_enet, coefs_positive_enet, _ = enet_path(
72+
X, y, eps=eps, l1_ratio=0.8, positive=True
73+
)
74+
75+
# Display results
76+
77+
plt.figure(1)
78+
colors = cycle(["b", "r", "g", "c", "k"])
79+
for coef_lasso, coef_lars, c in zip(coefs_lasso, coefs_lars, colors):
80+
l1 = plt.semilogx(alphas_lasso, coef_lasso, c=c)
81+
l2 = plt.semilogx(alphas_lars, coef_lars, linestyle="--", c=c)
82+
83+
plt.xlabel("alpha")
84+
plt.ylabel("coefficients")
85+
plt.title("Lasso and LARS Paths")
86+
plt.legend((l1[-1], l2[-1]), ("Lasso", "LARS"), loc="lower right")
87+
plt.axis("tight")
88+
89+
plt.figure(2)
90+
colors = cycle(["b", "r", "g", "c", "k"])
91+
for coef_l, coef_e, c in zip(coefs_lasso, coefs_enet, colors):
92+
l1 = plt.semilogx(alphas_lasso, coef_l, c=c)
93+
l2 = plt.semilogx(alphas_enet, coef_e, linestyle="--", c=c)
94+
95+
plt.xlabel("alpha")
96+
plt.ylabel("coefficients")
97+
plt.title("Lasso and Elastic-Net Paths")
98+
plt.legend((l1[-1], l2[-1]), ("Lasso", "Elastic-Net"), loc="lower right")
99+
plt.axis("tight")
100+
101+
102+
plt.figure(3)
103+
for coef_l, coef_pl, c in zip(coefs_lasso, coefs_positive_lasso, colors):
104+
l1 = plt.semilogy(alphas_lasso, coef_l, c=c)
105+
l2 = plt.semilogy(alphas_positive_lasso, coef_pl, linestyle="--", c=c)
106+
107+
plt.xlabel("alpha")
108+
plt.ylabel("coefficients")
109+
plt.title("Lasso and positive Lasso")
110+
plt.legend((l1[-1], l2[-1]), ("Lasso", "positive Lasso"), loc="lower right")
111+
plt.axis("tight")
112+
113+
114+
plt.figure(4)
115+
colors = cycle(["b", "r", "g", "c", "k"])
116+
for coef_lars, coef_positive_lars, c in zip(coefs_lars, coefs_positive_lars, colors):
117+
l1 = plt.semilogx(alphas_lars, coef_lars, c=c)
118+
l2 = plt.semilogx(alphas_positive_lars, coef_positive_lars, linestyle="--", c=c)
119+
120+
plt.xlabel("alpha")
121+
plt.ylabel("coefficients")
122+
plt.title("LARS and Positive LARS")
123+
plt.legend((l1[-1], l2[-1]), ("LARS", "Positive LARS"), loc="lower right")
124+
plt.axis("tight")
125+
126+
plt.figure(5)
127+
for coef_e, coef_pe, c in zip(coefs_enet, coefs_positive_enet, colors):
128+
l1 = plt.semilogx(alphas_enet, coef_e, c=c)
129+
l2 = plt.semilogx(alphas_positive_enet, coef_pe, linestyle="--", c=c)
130+
131+
plt.xlabel("alpha")
132+
plt.ylabel("coefficients")
133+
plt.title("Elastic-Net and positive Elastic-Net")
134+
plt.legend((l1[-1], l2[-1]), ("Elastic-Net", "positive Elastic-Net"), loc="lower right")
135+
plt.axis("tight")
136+
plt.show()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/4c4c075dc14e39d30d982d0b2818ea95/plot_lasso_coordinate_descent_path.ipynb

Lines changed: 0 additions & 43 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/9b30279eefb3398ed66923f02e087c20/plot_lasso_lars.py

Lines changed: 0 additions & 36 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dev/_downloads/aeeae45cd3cd50e5c66daa21027f9c2a/plot_lasso_lars.ipynb

Lines changed: 0 additions & 43 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)