Skip to content

Commit 852d854

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 2335a8e831b44b28f30cedb355bab6ac4803ef8b
1 parent 927e254 commit 852d854

File tree

1,264 files changed

+4432
-4639
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,264 files changed

+4432
-4639
lines changed
Binary file not shown.

dev/_downloads/18eb95af29bd5554020a8428b3ceac54/plot_cluster_iris.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Though the following import is not directly being used, it is required\n# for 3D projection to work with matplotlib < 3.2\nimport mpl_toolkits.mplot3d # noqa: F401\n\nfrom sklearn.cluster import KMeans\nfrom sklearn import datasets\n\nnp.random.seed(5)\n\niris = datasets.load_iris()\nX = iris.data\ny = iris.target\n\nestimators = [\n (\"k_means_iris_8\", KMeans(n_clusters=8)),\n (\"k_means_iris_3\", KMeans(n_clusters=3)),\n (\"k_means_iris_bad_init\", KMeans(n_clusters=3, n_init=1, init=\"random\")),\n]\n\nfignum = 1\ntitles = [\"8 clusters\", \"3 clusters\", \"3 clusters, bad initialization\"]\nfor name, est in estimators:\n fig = plt.figure(fignum, figsize=(4, 3))\n ax = fig.add_subplot(111, projection=\"3d\", elev=48, azim=134)\n ax.set_position([0, 0, 0.95, 1])\n est.fit(X)\n labels = est.labels_\n\n ax.scatter(X[:, 3], X[:, 0], X[:, 2], c=labels.astype(float), edgecolor=\"k\")\n\n ax.w_xaxis.set_ticklabels([])\n ax.w_yaxis.set_ticklabels([])\n ax.w_zaxis.set_ticklabels([])\n ax.set_xlabel(\"Petal width\")\n ax.set_ylabel(\"Sepal length\")\n ax.set_zlabel(\"Petal length\")\n ax.set_title(titles[fignum - 1])\n ax.dist = 12\n fignum = fignum + 1\n\n# Plot the ground truth\nfig = plt.figure(fignum, figsize=(4, 3))\nax = fig.add_subplot(111, projection=\"3d\", elev=48, azim=134)\nax.set_position([0, 0, 0.95, 1])\n\nfor name, label in [(\"Setosa\", 0), (\"Versicolour\", 1), (\"Virginica\", 2)]:\n ax.text3D(\n X[y == label, 3].mean(),\n X[y == label, 0].mean(),\n X[y == label, 2].mean() + 2,\n name,\n horizontalalignment=\"center\",\n bbox=dict(alpha=0.2, edgecolor=\"w\", facecolor=\"w\"),\n )\n# Reorder the labels to have colors matching the cluster results\ny = np.choose(y, [1, 2, 0]).astype(float)\nax.scatter(X[:, 3], X[:, 0], X[:, 2], c=y, edgecolor=\"k\")\n\nax.w_xaxis.set_ticklabels([])\nax.w_yaxis.set_ticklabels([])\nax.w_zaxis.set_ticklabels([])\nax.set_xlabel(\"Petal width\")\nax.set_ylabel(\"Sepal length\")\nax.set_zlabel(\"Petal length\")\nax.set_title(\"Ground Truth\")\nax.dist = 12\n\nfig.show()"
29+
"# Code source: Ga\u00ebl Varoquaux\n# Modified for documentation by Jaques Grobler\n# License: BSD 3 clause\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Though the following import is not directly being used, it is required\n# for 3D projection to work with matplotlib < 3.2\nimport mpl_toolkits.mplot3d # noqa: F401\n\nfrom sklearn.cluster import KMeans\nfrom sklearn import datasets\n\nnp.random.seed(5)\n\niris = datasets.load_iris()\nX = iris.data\ny = iris.target\n\nestimators = [\n (\"k_means_iris_8\", KMeans(n_clusters=8, n_init=\"auto\")),\n (\"k_means_iris_3\", KMeans(n_clusters=3, n_init=\"auto\")),\n (\"k_means_iris_bad_init\", KMeans(n_clusters=3, n_init=1, init=\"random\")),\n]\n\nfig = plt.figure(figsize=(10, 8))\ntitles = [\"8 clusters\", \"3 clusters\", \"3 clusters, bad initialization\"]\nfor idx, (name, est) in enumerate(estimators):\n ax = fig.add_subplot(2, 2, idx + 1, projection=\"3d\", elev=48, azim=134)\n est.fit(X)\n labels = est.labels_\n\n ax.scatter(X[:, 3], X[:, 0], X[:, 2], c=labels.astype(float), edgecolor=\"k\")\n\n ax.xaxis.set_ticklabels([])\n ax.yaxis.set_ticklabels([])\n ax.zaxis.set_ticklabels([])\n ax.set_xlabel(\"Petal width\")\n ax.set_ylabel(\"Sepal length\")\n ax.set_zlabel(\"Petal length\")\n ax.set_title(titles[idx - 1])\n\n# Plot the ground truth\nax = fig.add_subplot(2, 2, 4, projection=\"3d\", elev=48, azim=134)\n\nfor name, label in [(\"Setosa\", 0), (\"Versicolour\", 1), (\"Virginica\", 2)]:\n ax.text3D(\n X[y == label, 3].mean(),\n X[y == label, 0].mean(),\n X[y == label, 2].mean() + 2,\n name,\n horizontalalignment=\"center\",\n bbox=dict(alpha=0.2, edgecolor=\"w\", facecolor=\"w\"),\n )\n# Reorder the labels to have colors matching the cluster results\ny = np.choose(y, [1, 2, 0]).astype(float)\nax.scatter(X[:, 3], X[:, 0], X[:, 2], c=y, edgecolor=\"k\")\n\nax.xaxis.set_ticklabels([])\nax.yaxis.set_ticklabels([])\nax.zaxis.set_ticklabels([])\nax.set_xlabel(\"Petal width\")\nax.set_ylabel(\"Sepal length\")\nax.set_zlabel(\"Petal length\")\nax.set_title(\"Ground Truth\")\n\nplt.subplots_adjust(wspace=0.25, hspace=0.25)\nplt.show()"
3030
]
3131
}
3232
],
Binary file not shown.

dev/_downloads/a315e003c9ce53b89d5fa110538885fd/plot_cluster_iris.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,30 @@
3636
y = iris.target
3737

3838
estimators = [
39-
("k_means_iris_8", KMeans(n_clusters=8)),
40-
("k_means_iris_3", KMeans(n_clusters=3)),
39+
("k_means_iris_8", KMeans(n_clusters=8, n_init="auto")),
40+
("k_means_iris_3", KMeans(n_clusters=3, n_init="auto")),
4141
("k_means_iris_bad_init", KMeans(n_clusters=3, n_init=1, init="random")),
4242
]
4343

44-
fignum = 1
44+
fig = plt.figure(figsize=(10, 8))
4545
titles = ["8 clusters", "3 clusters", "3 clusters, bad initialization"]
46-
for name, est in estimators:
47-
fig = plt.figure(fignum, figsize=(4, 3))
48-
ax = fig.add_subplot(111, projection="3d", elev=48, azim=134)
49-
ax.set_position([0, 0, 0.95, 1])
46+
for idx, (name, est) in enumerate(estimators):
47+
ax = fig.add_subplot(2, 2, idx + 1, projection="3d", elev=48, azim=134)
5048
est.fit(X)
5149
labels = est.labels_
5250

5351
ax.scatter(X[:, 3], X[:, 0], X[:, 2], c=labels.astype(float), edgecolor="k")
5452

55-
ax.w_xaxis.set_ticklabels([])
56-
ax.w_yaxis.set_ticklabels([])
57-
ax.w_zaxis.set_ticklabels([])
53+
ax.xaxis.set_ticklabels([])
54+
ax.yaxis.set_ticklabels([])
55+
ax.zaxis.set_ticklabels([])
5856
ax.set_xlabel("Petal width")
5957
ax.set_ylabel("Sepal length")
6058
ax.set_zlabel("Petal length")
61-
ax.set_title(titles[fignum - 1])
62-
ax.dist = 12
63-
fignum = fignum + 1
59+
ax.set_title(titles[idx - 1])
6460

6561
# Plot the ground truth
66-
fig = plt.figure(fignum, figsize=(4, 3))
67-
ax = fig.add_subplot(111, projection="3d", elev=48, azim=134)
68-
ax.set_position([0, 0, 0.95, 1])
62+
ax = fig.add_subplot(2, 2, 4, projection="3d", elev=48, azim=134)
6963

7064
for name, label in [("Setosa", 0), ("Versicolour", 1), ("Virginica", 2)]:
7165
ax.text3D(
@@ -80,13 +74,13 @@
8074
y = np.choose(y, [1, 2, 0]).astype(float)
8175
ax.scatter(X[:, 3], X[:, 0], X[:, 2], c=y, edgecolor="k")
8276

83-
ax.w_xaxis.set_ticklabels([])
84-
ax.w_yaxis.set_ticklabels([])
85-
ax.w_zaxis.set_ticklabels([])
77+
ax.xaxis.set_ticklabels([])
78+
ax.yaxis.set_ticklabels([])
79+
ax.zaxis.set_ticklabels([])
8680
ax.set_xlabel("Petal width")
8781
ax.set_ylabel("Sepal length")
8882
ax.set_zlabel("Petal length")
8983
ax.set_title("Ground Truth")
90-
ax.dist = 12
9184

92-
fig.show()
85+
plt.subplots_adjust(wspace=0.25, hspace=0.25)
86+
plt.show()

dev/_downloads/scikit-learn-docs.zip

-7.4 KB
Binary file not shown.
-27 Bytes
-204 Bytes
68 Bytes
59 Bytes
14 Bytes

0 commit comments

Comments
 (0)