Skip to content

Commit 277e258

Browse files
committed
Pushing the docs to 1.5/ for branch: 1.5.X, commit 70fdc843a4b8182d97a3508c1a426acc5e87e980
1 parent cc554f4 commit 277e258

File tree

1,606 files changed

+286195
-315385
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,606 files changed

+286195
-315385
lines changed

1.5/.buildinfo

+1-1
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: 2907958f5ac8f0a65d5062369d2dcd04
3+
config: d957078dbf4c58a2fce77ff0dd5a988d
44
tags: 645f666f9bcd5a90fca523b33c5a78b7

1.5/_downloads/00ae629d652473137a3905a5e08ea815/plot_iris_dtc.py

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
X[idx, 1],
6767
c=color,
6868
label=iris.target_names[i],
69-
cmap=plt.cm.RdYlBu,
7069
edgecolor="black",
7170
s=15,
7271
)
Binary file not shown.

1.5/_downloads/1b3f17ff0f112d5b77cbdb90f1c17046/plot_set_output.py

+15
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@
6363
# means that the final logistic regression step contains the feature names of the input.
6464
clf[-1].feature_names_in_
6565

66+
# %%
67+
# .. note:: If one uses the method `set_params`, the transformer will be
68+
# replaced by a new one with the default output format.
69+
clf.set_params(standardscaler=StandardScaler())
70+
clf.fit(X_train, y_train)
71+
clf[-1].feature_names_in_
72+
73+
# %%
74+
# To keep the intended behavior, use `set_output` on the new transformer
75+
# beforehand
76+
scaler = StandardScaler().set_output(transform="pandas")
77+
clf.set_params(standardscaler=scaler)
78+
clf.fit(X_train, y_train)
79+
clf[-1].feature_names_in_
80+
6681
# %%
6782
# Next we load the titanic dataset to demonstrate `set_output` with
6883
# :class:`compose.ColumnTransformer` and heterogeneous data.

1.5/_downloads/1f682002d8b68c290d9d03599368e83d/plot_lasso_coordinate_descent_path.py

+12-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from itertools import cycle
1717

1818
import matplotlib.pyplot as plt
19-
import numpy as np
2019

2120
from sklearn import datasets
2221
from sklearn.linear_model import enet_path, lasso_path
@@ -49,41 +48,37 @@
4948

5049
plt.figure(1)
5150
colors = cycle(["b", "r", "g", "c", "k"])
52-
neg_log_alphas_lasso = -np.log10(alphas_lasso)
53-
neg_log_alphas_enet = -np.log10(alphas_enet)
5451
for coef_l, coef_e, c in zip(coefs_lasso, coefs_enet, colors):
55-
l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c)
56-
l2 = plt.plot(neg_log_alphas_enet, coef_e, linestyle="--", c=c)
52+
l1 = plt.semilogx(alphas_lasso, coef_l, c=c)
53+
l2 = plt.semilogx(alphas_enet, coef_e, linestyle="--", c=c)
5754

58-
plt.xlabel("-Log(alpha)")
55+
plt.xlabel("alpha")
5956
plt.ylabel("coefficients")
6057
plt.title("Lasso and Elastic-Net Paths")
61-
plt.legend((l1[-1], l2[-1]), ("Lasso", "Elastic-Net"), loc="lower left")
58+
plt.legend((l1[-1], l2[-1]), ("Lasso", "Elastic-Net"), loc="lower right")
6259
plt.axis("tight")
6360

6461

6562
plt.figure(2)
66-
neg_log_alphas_positive_lasso = -np.log10(alphas_positive_lasso)
6763
for coef_l, coef_pl, c in zip(coefs_lasso, coefs_positive_lasso, colors):
68-
l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c)
69-
l2 = plt.plot(neg_log_alphas_positive_lasso, coef_pl, linestyle="--", c=c)
64+
l1 = plt.semilogy(alphas_lasso, coef_l, c=c)
65+
l2 = plt.semilogy(alphas_positive_lasso, coef_pl, linestyle="--", c=c)
7066

71-
plt.xlabel("-Log(alpha)")
67+
plt.xlabel("alpha")
7268
plt.ylabel("coefficients")
7369
plt.title("Lasso and positive Lasso")
74-
plt.legend((l1[-1], l2[-1]), ("Lasso", "positive Lasso"), loc="lower left")
70+
plt.legend((l1[-1], l2[-1]), ("Lasso", "positive Lasso"), loc="lower right")
7571
plt.axis("tight")
7672

7773

7874
plt.figure(3)
79-
neg_log_alphas_positive_enet = -np.log10(alphas_positive_enet)
8075
for coef_e, coef_pe, c in zip(coefs_enet, coefs_positive_enet, colors):
81-
l1 = plt.plot(neg_log_alphas_enet, coef_e, c=c)
82-
l2 = plt.plot(neg_log_alphas_positive_enet, coef_pe, linestyle="--", c=c)
76+
l1 = plt.semilogx(alphas_enet, coef_e, c=c)
77+
l2 = plt.semilogx(alphas_positive_enet, coef_pe, linestyle="--", c=c)
8378

84-
plt.xlabel("-Log(alpha)")
79+
plt.xlabel("alpha")
8580
plt.ylabel("coefficients")
8681
plt.title("Elastic-Net and positive Elastic-Net")
87-
plt.legend((l1[-1], l2[-1]), ("Elastic-Net", "positive Elastic-Net"), loc="lower left")
82+
plt.legend((l1[-1], l2[-1]), ("Elastic-Net", "positive Elastic-Net"), loc="lower right")
8883
plt.axis("tight")
8984
plt.show()

1.5/_downloads/49cd91d05440a1c88b074430761aeb76/plot_cv_indices.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
"outputs": [],
5353
"source": [
54-
"def plot_cv_indices(cv, X, y, group, ax, n_splits, lw=10):\n \"\"\"Create a sample plot for indices of a cross-validation object.\"\"\"\n\n # Generate the training/testing visualizations for each CV split\n for ii, (tr, tt) in enumerate(cv.split(X=X, y=y, groups=group)):\n # Fill in indices with the training/test groups\n indices = np.array([np.nan] * len(X))\n indices[tt] = 1\n indices[tr] = 0\n\n # Visualize the results\n ax.scatter(\n range(len(indices)),\n [ii + 0.5] * len(indices),\n c=indices,\n marker=\"_\",\n lw=lw,\n cmap=cmap_cv,\n vmin=-0.2,\n vmax=1.2,\n )\n\n # Plot the data classes and groups at the end\n ax.scatter(\n range(len(X)), [ii + 1.5] * len(X), c=y, marker=\"_\", lw=lw, cmap=cmap_data\n )\n\n ax.scatter(\n range(len(X)), [ii + 2.5] * len(X), c=group, marker=\"_\", lw=lw, cmap=cmap_data\n )\n\n # Formatting\n yticklabels = list(range(n_splits)) + [\"class\", \"group\"]\n ax.set(\n yticks=np.arange(n_splits + 2) + 0.5,\n yticklabels=yticklabels,\n xlabel=\"Sample index\",\n ylabel=\"CV iteration\",\n ylim=[n_splits + 2.2, -0.2],\n xlim=[0, 100],\n )\n ax.set_title(\"{}\".format(type(cv).__name__), fontsize=15)\n return ax"
54+
"def plot_cv_indices(cv, X, y, group, ax, n_splits, lw=10):\n \"\"\"Create a sample plot for indices of a cross-validation object.\"\"\"\n use_groups = \"Group\" in type(cv).__name__\n groups = group if use_groups else None\n # Generate the training/testing visualizations for each CV split\n for ii, (tr, tt) in enumerate(cv.split(X=X, y=y, groups=groups)):\n # Fill in indices with the training/test groups\n indices = np.array([np.nan] * len(X))\n indices[tt] = 1\n indices[tr] = 0\n\n # Visualize the results\n ax.scatter(\n range(len(indices)),\n [ii + 0.5] * len(indices),\n c=indices,\n marker=\"_\",\n lw=lw,\n cmap=cmap_cv,\n vmin=-0.2,\n vmax=1.2,\n )\n\n # Plot the data classes and groups at the end\n ax.scatter(\n range(len(X)), [ii + 1.5] * len(X), c=y, marker=\"_\", lw=lw, cmap=cmap_data\n )\n\n ax.scatter(\n range(len(X)), [ii + 2.5] * len(X), c=group, marker=\"_\", lw=lw, cmap=cmap_data\n )\n\n # Formatting\n yticklabels = list(range(n_splits)) + [\"class\", \"group\"]\n ax.set(\n yticks=np.arange(n_splits + 2) + 0.5,\n yticklabels=yticklabels,\n xlabel=\"Sample index\",\n ylabel=\"CV iteration\",\n ylim=[n_splits + 2.2, -0.2],\n xlim=[0, 100],\n )\n ax.set_title(\"{}\".format(type(cv).__name__), fontsize=15)\n return ax"
5555
]
5656
},
5757
{

1.5/_downloads/4c1663175b07cf9608b07331aa180eb7/plot_logistic_multinomial.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"outputs": [],
1717
"source": [
18-
"# Authors: Tom Dupre la Tour <[email protected]>\n# License: BSD 3 clause\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom sklearn.datasets import make_blobs\nfrom sklearn.inspection import DecisionBoundaryDisplay\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.multiclass import OneVsRestClassifier\n\n# make 3-class dataset for classification\ncenters = [[-5, 0], [0, 1.5], [5, -1]]\nX, y = make_blobs(n_samples=1000, centers=centers, random_state=40)\ntransformation = [[0.4, 0.2], [-0.4, 1.2]]\nX = np.dot(X, transformation)\n\nfor multi_class in (\"multinomial\", \"ovr\"):\n clf = LogisticRegression(solver=\"sag\", max_iter=100, random_state=42)\n if multi_class == \"ovr\":\n clf = OneVsRestClassifier(clf)\n clf.fit(X, y)\n\n # print the training scores\n print(\"training score : %.3f (%s)\" % (clf.score(X, y), multi_class))\n\n _, ax = plt.subplots()\n DecisionBoundaryDisplay.from_estimator(\n clf, X, response_method=\"predict\", cmap=plt.cm.Paired, ax=ax\n )\n plt.title(\"Decision surface of LogisticRegression (%s)\" % multi_class)\n plt.axis(\"tight\")\n\n # Plot also the training points\n colors = \"bry\"\n for i, color in zip(clf.classes_, colors):\n idx = np.where(y == i)\n plt.scatter(\n X[idx, 0], X[idx, 1], c=color, cmap=plt.cm.Paired, edgecolor=\"black\", s=20\n )\n\n # Plot the three one-against-all classifiers\n xmin, xmax = plt.xlim()\n ymin, ymax = plt.ylim()\n if multi_class == \"ovr\":\n coef = np.concatenate([est.coef_ for est in clf.estimators_])\n intercept = np.concatenate([est.intercept_ for est in clf.estimators_])\n else:\n coef = clf.coef_\n intercept = clf.intercept_\n\n def plot_hyperplane(c, color):\n def line(x0):\n return (-(x0 * coef[c, 0]) - intercept[c]) / coef[c, 1]\n\n plt.plot([xmin, xmax], [line(xmin), line(xmax)], ls=\"--\", color=color)\n\n for i, color in zip(clf.classes_, colors):\n plot_hyperplane(i, color)\n\nplt.show()"
18+
"# Authors: Tom Dupre la Tour <[email protected]>\n# License: BSD 3 clause\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom sklearn.datasets import make_blobs\nfrom sklearn.inspection import DecisionBoundaryDisplay\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.multiclass import OneVsRestClassifier\n\n# make 3-class dataset for classification\ncenters = [[-5, 0], [0, 1.5], [5, -1]]\nX, y = make_blobs(n_samples=1000, centers=centers, random_state=40)\ntransformation = [[0.4, 0.2], [-0.4, 1.2]]\nX = np.dot(X, transformation)\n\nfor multi_class in (\"multinomial\", \"ovr\"):\n clf = LogisticRegression(solver=\"sag\", max_iter=100, random_state=42)\n if multi_class == \"ovr\":\n clf = OneVsRestClassifier(clf)\n clf.fit(X, y)\n\n # print the training scores\n print(\"training score : %.3f (%s)\" % (clf.score(X, y), multi_class))\n\n _, ax = plt.subplots()\n DecisionBoundaryDisplay.from_estimator(\n clf, X, response_method=\"predict\", cmap=plt.cm.Paired, ax=ax\n )\n plt.title(\"Decision surface of LogisticRegression (%s)\" % multi_class)\n plt.axis(\"tight\")\n\n # Plot also the training points\n colors = \"bry\"\n for i, color in zip(clf.classes_, colors):\n idx = np.where(y == i)\n plt.scatter(X[idx, 0], X[idx, 1], c=color, edgecolor=\"black\", s=20)\n\n # Plot the three one-against-all classifiers\n xmin, xmax = plt.xlim()\n ymin, ymax = plt.ylim()\n if multi_class == \"ovr\":\n coef = np.concatenate([est.coef_ for est in clf.estimators_])\n intercept = np.concatenate([est.intercept_ for est in clf.estimators_])\n else:\n coef = clf.coef_\n intercept = clf.intercept_\n\n def plot_hyperplane(c, color):\n def line(x0):\n return (-(x0 * coef[c, 0]) - intercept[c]) / coef[c, 1]\n\n plt.plot([xmin, xmax], [line(xmin), line(xmax)], ls=\"--\", color=color)\n\n for i, color in zip(clf.classes_, colors):\n plot_hyperplane(i, color)\n\nplt.show()"
1919
]
2020
}
2121
],

1.5/_downloads/4c4c075dc14e39d30d982d0b2818ea95/plot_lasso_coordinate_descent_path.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"outputs": [],
1717
"source": [
18-
"# Author: Alexandre Gramfort <[email protected]>\n# License: BSD 3 clause\n\nfrom itertools import cycle\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom sklearn import datasets\nfrom sklearn.linear_model import enet_path, lasso_path\n\nX, y = datasets.load_diabetes(return_X_y=True)\n\n\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)\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\"])\nneg_log_alphas_lasso = -np.log10(alphas_lasso)\nneg_log_alphas_enet = -np.log10(alphas_enet)\nfor coef_l, coef_e, c in zip(coefs_lasso, coefs_enet, colors):\n l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c)\n l2 = plt.plot(neg_log_alphas_enet, coef_e, linestyle=\"--\", c=c)\n\nplt.xlabel(\"-Log(alpha)\")\nplt.ylabel(\"coefficients\")\nplt.title(\"Lasso and Elastic-Net Paths\")\nplt.legend((l1[-1], l2[-1]), (\"Lasso\", \"Elastic-Net\"), loc=\"lower left\")\nplt.axis(\"tight\")\n\n\nplt.figure(2)\nneg_log_alphas_positive_lasso = -np.log10(alphas_positive_lasso)\nfor coef_l, coef_pl, c in zip(coefs_lasso, coefs_positive_lasso, colors):\n l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c)\n l2 = plt.plot(neg_log_alphas_positive_lasso, coef_pl, linestyle=\"--\", c=c)\n\nplt.xlabel(\"-Log(alpha)\")\nplt.ylabel(\"coefficients\")\nplt.title(\"Lasso and positive Lasso\")\nplt.legend((l1[-1], l2[-1]), (\"Lasso\", \"positive Lasso\"), loc=\"lower left\")\nplt.axis(\"tight\")\n\n\nplt.figure(3)\nneg_log_alphas_positive_enet = -np.log10(alphas_positive_enet)\nfor coef_e, coef_pe, c in zip(coefs_enet, coefs_positive_enet, colors):\n l1 = plt.plot(neg_log_alphas_enet, coef_e, c=c)\n l2 = plt.plot(neg_log_alphas_positive_enet, coef_pe, linestyle=\"--\", c=c)\n\nplt.xlabel(\"-Log(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 left\")\nplt.axis(\"tight\")\nplt.show()"
18+
"# Author: Alexandre Gramfort <[email protected]>\n# License: BSD 3 clause\n\nfrom itertools import cycle\n\nimport matplotlib.pyplot as plt\n\nfrom sklearn import datasets\nfrom sklearn.linear_model import enet_path, lasso_path\n\nX, y = datasets.load_diabetes(return_X_y=True)\n\n\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)\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_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(2)\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(3)\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()"
1919
]
2020
}
2121
],

1.5/_downloads/4ddbef459f3a80ccda29978b8cb0ef79/plot_digits_last_image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
first transform it into a feature vector with length 64.
1010
1111
See `here
12-
<https://archive.ics.uci.edu/ml/datasets/Pen-Based+Recognition+of+Handwritten+Digits>`_
12+
<https://archive.ics.uci.edu/dataset/81/pen+based+recognition+of+handwritten+digits>`_
1313
for more information about this dataset.
1414
1515
"""
Binary file not shown.

1.5/_downloads/79791c0d96848daf4df02b5b61ced25d/plot_digits_last_image.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"\n# The Digit Dataset\n\nThis dataset is made up of 1797 8x8 images. Each image,\nlike the one shown below, is of a hand-written digit.\nIn order to utilize an 8x8 figure like this, we'd have to\nfirst transform it into a feature vector with length 64.\n\nSee [here](https://archive.ics.uci.edu/ml/datasets/Pen-Based+Recognition+of+Handwritten+Digits)\nfor more information about this dataset.\n"
7+
"\n# The Digit Dataset\n\nThis dataset is made up of 1797 8x8 images. Each image,\nlike the one shown below, is of a hand-written digit.\nIn order to utilize an 8x8 figure like this, we'd have to\nfirst transform it into a feature vector with length 64.\n\nSee [here](https://archive.ics.uci.edu/dataset/81/pen+based+recognition+of+handwritten+digits)\nfor more information about this dataset.\n"
88
]
99
},
1010
{

1.5/_downloads/85c522d0f7149f3e8274112a6d62256f/plot_logistic_multinomial.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
colors = "bry"
4747
for i, color in zip(clf.classes_, colors):
4848
idx = np.where(y == i)
49-
plt.scatter(
50-
X[idx, 0], X[idx, 1], c=color, cmap=plt.cm.Paired, edgecolor="black", s=20
51-
)
49+
plt.scatter(X[idx, 0], X[idx, 1], c=color, edgecolor="black", s=20)
5250

5351
# Plot the three one-against-all classifiers
5452
xmin, xmax = plt.xlim()

0 commit comments

Comments
 (0)