Skip to content

Commit 92f09e0

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 18c1972eb9637034b8e9fbd0df966c10058770f5
1 parent a4fb74d commit 92f09e0

File tree

1,335 files changed

+7194
-7718
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,335 files changed

+7194
-7718
lines changed

dev/.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: 8e49001559d8412c6c31e2e5ae0dd686
3+
config: 1f0325ead478dd709d7d2aa77cd5a9b0
44
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file not shown.

dev/_downloads/264f6891fa2130246a013d5f089e7b2e/plot_svm_kernels.ipynb

+26-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
"outputs": [],
5353
"source": [
54-
"from sklearn import svm\nfrom sklearn.inspection import DecisionBoundaryDisplay\n\n\ndef plot_training_data_with_decision_boundary(kernel):\n # Train the SVC\n clf = svm.SVC(kernel=kernel, gamma=2).fit(X, y)\n\n # Settings for plotting\n _, ax = plt.subplots(figsize=(4, 3))\n x_min, x_max, y_min, y_max = -3, 3, -3, 3\n ax.set(xlim=(x_min, x_max), ylim=(y_min, y_max))\n\n # Plot decision boundary and margins\n common_params = {\"estimator\": clf, \"X\": X, \"ax\": ax}\n DecisionBoundaryDisplay.from_estimator(\n **common_params,\n response_method=\"predict\",\n plot_method=\"pcolormesh\",\n alpha=0.3,\n )\n DecisionBoundaryDisplay.from_estimator(\n **common_params,\n response_method=\"decision_function\",\n plot_method=\"contour\",\n levels=[-1, 0, 1],\n colors=[\"k\", \"k\", \"k\"],\n linestyles=[\"--\", \"-\", \"--\"],\n )\n\n # Plot bigger circles around samples that serve as support vectors\n ax.scatter(\n clf.support_vectors_[:, 0],\n clf.support_vectors_[:, 1],\n s=250,\n facecolors=\"none\",\n edgecolors=\"k\",\n )\n # Plot samples by color and add legend\n ax.scatter(X[:, 0], X[:, 1], c=y, s=150, edgecolors=\"k\")\n ax.legend(*scatter.legend_elements(), loc=\"upper right\", title=\"Classes\")\n ax.set_title(f\" Decision boundaries of {kernel} kernel in SVC\")\n\n _ = plt.show()"
54+
"from sklearn import svm\nfrom sklearn.inspection import DecisionBoundaryDisplay\n\n\ndef plot_training_data_with_decision_boundary(\n kernel, ax=None, long_title=True, support_vectors=True\n):\n # Train the SVC\n clf = svm.SVC(kernel=kernel, gamma=2).fit(X, y)\n\n # Settings for plotting\n if ax is None:\n _, ax = plt.subplots(figsize=(4, 3))\n x_min, x_max, y_min, y_max = -3, 3, -3, 3\n ax.set(xlim=(x_min, x_max), ylim=(y_min, y_max))\n\n # Plot decision boundary and margins\n common_params = {\"estimator\": clf, \"X\": X, \"ax\": ax}\n DecisionBoundaryDisplay.from_estimator(\n **common_params,\n response_method=\"predict\",\n plot_method=\"pcolormesh\",\n alpha=0.3,\n )\n DecisionBoundaryDisplay.from_estimator(\n **common_params,\n response_method=\"decision_function\",\n plot_method=\"contour\",\n levels=[-1, 0, 1],\n colors=[\"k\", \"k\", \"k\"],\n linestyles=[\"--\", \"-\", \"--\"],\n )\n\n if support_vectors:\n # Plot bigger circles around samples that serve as support vectors\n ax.scatter(\n clf.support_vectors_[:, 0],\n clf.support_vectors_[:, 1],\n s=150,\n facecolors=\"none\",\n edgecolors=\"k\",\n )\n\n # Plot samples by color and add legend\n ax.scatter(X[:, 0], X[:, 1], c=y, s=30, edgecolors=\"k\")\n ax.legend(*scatter.legend_elements(), loc=\"upper right\", title=\"Classes\")\n if long_title:\n ax.set_title(f\" Decision boundaries of {kernel} kernel in SVC\")\n else:\n ax.set_title(kernel)\n\n if ax is None:\n plt.show()"
5555
]
5656
},
5757
{
@@ -132,6 +132,31 @@
132132
"source": [
133133
"We can see that the decision boundaries obtained with the sigmoid kernel\nappear curved and irregular. The decision boundary tries to separate the\nclasses by fitting a sigmoid-shaped curve, resulting in a complex boundary\nthat may not generalize well to unseen data. From this example it becomes\nobvious, that the sigmoid kernel has very specific use cases, when dealing\nwith data that exhibits a sigmoidal shape. In this example, careful fine\ntuning might find more generalizable decision boundaries. Because of it's\nspecificity, the sigmoid kernel is less commonly used in practice compared to\nother kernels.\n\n## Conclusion\nIn this example, we have visualized the decision boundaries trained with the\nprovided dataset. The plots serve as an intuitive demonstration of how\ndifferent kernels utilize the training data to determine the classification\nboundaries.\n\nThe hyperplanes and margins, although computed indirectly, can be imagined as\nplanes in the transformed feature space. However, in the plots, they are\nrepresented relative to the original feature space, resulting in curved\ndecision boundaries for the polynomial, RBF, and sigmoid kernels.\n\nPlease note that the plots do not evaluate the individual kernel's accuracy or\nquality. They are intended to provide a visual understanding of how the\ndifferent kernels use the training data.\n\nFor a comprehensive evaluation, fine-tuning of :class:`~sklearn.svm.SVC`\nparameters using techniques such as\n:class:`~sklearn.model_selection.GridSearchCV` is recommended to capture the\nunderlying structures within the data.\n\n"
134134
]
135+
},
136+
{
137+
"cell_type": "markdown",
138+
"metadata": {},
139+
"source": [
140+
"## XOR dataset\nA classical example of a dataset which is not linearly separable is the XOR\npattern. HEre we demonstrate how different kernels work on such a dataset.\n\n"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": null,
146+
"metadata": {
147+
"collapsed": false
148+
},
149+
"outputs": [],
150+
"source": [
151+
"xx, yy = np.meshgrid(np.linspace(-3, 3, 500), np.linspace(-3, 3, 500))\nnp.random.seed(0)\nX = np.random.randn(300, 2)\ny = np.logical_xor(X[:, 0] > 0, X[:, 1] > 0)\n\n_, ax = plt.subplots(2, 2, figsize=(8, 8))\nargs = dict(long_title=False, support_vectors=False)\nplot_training_data_with_decision_boundary(\"linear\", ax[0, 0], **args)\nplot_training_data_with_decision_boundary(\"poly\", ax[0, 1], **args)\nplot_training_data_with_decision_boundary(\"rbf\", ax[1, 0], **args)\nplot_training_data_with_decision_boundary(\"sigmoid\", ax[1, 1], **args)\nplt.show()"
152+
]
153+
},
154+
{
155+
"cell_type": "markdown",
156+
"metadata": {},
157+
"source": [
158+
"As you can see from the plots above, only the `rbf` kernel can find a\nreasonable decision boundary for the above dataset.\n\n"
159+
]
135160
}
136161
],
137162
"metadata": {
Binary file not shown.

dev/_downloads/8975399471ae75debd0b26fbe3013719/plot_svm_kernels.py

+45-14
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,15 @@
110110
from sklearn.inspection import DecisionBoundaryDisplay
111111

112112

113-
def plot_training_data_with_decision_boundary(kernel):
113+
def plot_training_data_with_decision_boundary(
114+
kernel, ax=None, long_title=True, support_vectors=True
115+
):
114116
# Train the SVC
115117
clf = svm.SVC(kernel=kernel, gamma=2).fit(X, y)
116118

117119
# Settings for plotting
118-
_, ax = plt.subplots(figsize=(4, 3))
120+
if ax is None:
121+
_, ax = plt.subplots(figsize=(4, 3))
119122
x_min, x_max, y_min, y_max = -3, 3, -3, 3
120123
ax.set(xlim=(x_min, x_max), ylim=(y_min, y_max))
121124

@@ -136,20 +139,26 @@ def plot_training_data_with_decision_boundary(kernel):
136139
linestyles=["--", "-", "--"],
137140
)
138141

139-
# Plot bigger circles around samples that serve as support vectors
140-
ax.scatter(
141-
clf.support_vectors_[:, 0],
142-
clf.support_vectors_[:, 1],
143-
s=250,
144-
facecolors="none",
145-
edgecolors="k",
146-
)
142+
if support_vectors:
143+
# Plot bigger circles around samples that serve as support vectors
144+
ax.scatter(
145+
clf.support_vectors_[:, 0],
146+
clf.support_vectors_[:, 1],
147+
s=150,
148+
facecolors="none",
149+
edgecolors="k",
150+
)
151+
147152
# Plot samples by color and add legend
148-
ax.scatter(X[:, 0], X[:, 1], c=y, s=150, edgecolors="k")
153+
ax.scatter(X[:, 0], X[:, 1], c=y, s=30, edgecolors="k")
149154
ax.legend(*scatter.legend_elements(), loc="upper right", title="Classes")
150-
ax.set_title(f" Decision boundaries of {kernel} kernel in SVC")
155+
if long_title:
156+
ax.set_title(f" Decision boundaries of {kernel} kernel in SVC")
157+
else:
158+
ax.set_title(kernel)
151159

152-
_ = plt.show()
160+
if ax is None:
161+
plt.show()
153162

154163

155164
# %%
@@ -237,7 +246,6 @@ def plot_training_data_with_decision_boundary(kernel):
237246
# using the hyperbolic tangent function (:math:`\tanh`). The kernel function
238247
# scales and possibly shifts the dot product of the two points
239248
# (:math:`\mathbf{x}_1` and :math:`\mathbf{x}_2`).
240-
241249
plot_training_data_with_decision_boundary("sigmoid")
242250

243251
# %%
@@ -271,3 +279,26 @@ def plot_training_data_with_decision_boundary(kernel):
271279
# parameters using techniques such as
272280
# :class:`~sklearn.model_selection.GridSearchCV` is recommended to capture the
273281
# underlying structures within the data.
282+
283+
# %%
284+
# XOR dataset
285+
# -----------
286+
# A classical example of a dataset which is not linearly separable is the XOR
287+
# pattern. HEre we demonstrate how different kernels work on such a dataset.
288+
289+
xx, yy = np.meshgrid(np.linspace(-3, 3, 500), np.linspace(-3, 3, 500))
290+
np.random.seed(0)
291+
X = np.random.randn(300, 2)
292+
y = np.logical_xor(X[:, 0] > 0, X[:, 1] > 0)
293+
294+
_, ax = plt.subplots(2, 2, figsize=(8, 8))
295+
args = dict(long_title=False, support_vectors=False)
296+
plot_training_data_with_decision_boundary("linear", ax[0, 0], **args)
297+
plot_training_data_with_decision_boundary("poly", ax[0, 1], **args)
298+
plot_training_data_with_decision_boundary("rbf", ax[1, 0], **args)
299+
plot_training_data_with_decision_boundary("sigmoid", ax[1, 1], **args)
300+
plt.show()
301+
302+
# %%
303+
# As you can see from the plots above, only the `rbf` kernel can find a
304+
# reasonable decision boundary for the above dataset.

dev/_downloads/8aa42a9df15e5712b4b0d5161f6ea6e9/plot_svm_nonlinear.ipynb

-43
This file was deleted.

dev/_downloads/e8efe2a99bfe31c0f78509cb952cc8d5/plot_svm_nonlinear.py

-45
This file was deleted.

dev/_downloads/scikit-learn-docs.zip

-31.9 KB
Binary file not shown.
-100 Bytes
192 Bytes
-26 Bytes
9 Bytes
-4 Bytes
-578 Bytes
-16 Bytes
-25 Bytes
-110 Bytes
-180 Bytes
-996 Bytes
5.27 KB
-22 Bytes
-88 Bytes
-76 Bytes
-84 Bytes
-51 Bytes
52 Bytes
-234 Bytes
89 Bytes
2 Bytes
-29 Bytes
-553 Bytes
-616 Bytes
-711 Bytes
-734 Bytes
-176 Bytes
194 Bytes
-3.1 KB
-2.87 KB
-3.17 KB
-2.3 KB
190 KB
-102 KB
Binary file not shown.
-91.7 KB
Binary file not shown.
63 Bytes
-29 Bytes
27 Bytes

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

+1-1

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

+1-1

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

+4-4

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

+15-15

0 commit comments

Comments
 (0)