Skip to content

Commit c66c11a

Browse files
committed
Pushing the docs to dev/ for branch: main, commit ca2b14b744679a9066e4579a38b0085733be802e
1 parent dc22599 commit c66c11a

File tree

1,217 files changed

+4237
-4240
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,217 files changed

+4237
-4240
lines changed
Binary file not shown.
Binary file not shown.

dev/_downloads/a373b9fdc21005d9a66ecf3df90eb49a/plot_birch_vs_minibatchkmeans.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-
"# Authors: Manoj Kumar <[email protected]\n# Alexandre Gramfort <[email protected]>\n# License: BSD 3 clause\n\nfrom joblib import cpu_count\nfrom itertools import cycle\nfrom time import time\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.colors as colors\n\nfrom sklearn.cluster import Birch, MiniBatchKMeans\nfrom sklearn.datasets import make_blobs\n\n\n# Generate centers for the blobs so that it forms a 10 X 10 grid.\nxx = np.linspace(-22, 22, 10)\nyy = np.linspace(-22, 22, 10)\nxx, yy = np.meshgrid(xx, yy)\nn_centers = np.hstack((np.ravel(xx)[:, np.newaxis], np.ravel(yy)[:, np.newaxis]))\n\n# Generate blobs to do a comparison between MiniBatchKMeans and BIRCH.\nX, y = make_blobs(n_samples=25000, centers=n_centers, random_state=0)\n\n# Use all colors that matplotlib provides by default.\ncolors_ = cycle(colors.cnames.keys())\n\nfig = plt.figure(figsize=(12, 4))\nfig.subplots_adjust(left=0.04, right=0.98, bottom=0.1, top=0.9)\n\n# Compute clustering with BIRCH with and without the final clustering step\n# and plot.\nbirch_models = [\n Birch(threshold=1.7, n_clusters=None),\n Birch(threshold=1.7, n_clusters=100),\n]\nfinal_step = [\"without global clustering\", \"with global clustering\"]\n\nfor ind, (birch_model, info) in enumerate(zip(birch_models, final_step)):\n t = time()\n birch_model.fit(X)\n time_ = time() - t\n print(\"BIRCH %s as the final step took %0.2f seconds\" % (info, (time() - t)))\n\n # Plot result\n labels = birch_model.labels_\n centroids = birch_model.subcluster_centers_\n n_clusters = np.unique(labels).size\n print(\"n_clusters : %d\" % n_clusters)\n\n ax = fig.add_subplot(1, 3, ind + 1)\n for this_centroid, k, col in zip(centroids, range(n_clusters), colors_):\n mask = labels == k\n ax.scatter(X[mask, 0], X[mask, 1], c=\"w\", edgecolor=col, marker=\".\", alpha=0.5)\n if birch_model.n_clusters is None:\n ax.scatter(this_centroid[0], this_centroid[1], marker=\"+\", c=\"k\", s=25)\n ax.set_ylim([-25, 25])\n ax.set_xlim([-25, 25])\n ax.set_autoscaley_on(False)\n ax.set_title(\"BIRCH %s\" % info)\n\n# Compute clustering with MiniBatchKMeans.\nmbk = MiniBatchKMeans(\n init=\"k-means++\",\n n_clusters=100,\n batch_size=256 * cpu_count(),\n n_init=10,\n max_no_improvement=10,\n verbose=0,\n random_state=0,\n)\nt0 = time()\nmbk.fit(X)\nt_mini_batch = time() - t0\nprint(\"Time taken to run MiniBatchKMeans %0.2f seconds\" % t_mini_batch)\nmbk_means_labels_unique = np.unique(mbk.labels_)\n\nax = fig.add_subplot(1, 3, 3)\nfor this_centroid, k, col in zip(mbk.cluster_centers_, range(n_clusters), colors_):\n mask = mbk.labels_ == k\n ax.scatter(X[mask, 0], X[mask, 1], marker=\".\", c=\"w\", edgecolor=col, alpha=0.5)\n ax.scatter(this_centroid[0], this_centroid[1], marker=\"+\", c=\"k\", s=25)\nax.set_xlim([-25, 25])\nax.set_ylim([-25, 25])\nax.set_title(\"MiniBatchKMeans\")\nax.set_autoscaley_on(False)\nplt.show()"
29+
"# Authors: Manoj Kumar <[email protected]\n# Alexandre Gramfort <[email protected]>\n# License: BSD 3 clause\n\nfrom joblib import cpu_count\nfrom itertools import cycle\nfrom time import time\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.colors as colors\n\nfrom sklearn.cluster import Birch, MiniBatchKMeans\nfrom sklearn.datasets import make_blobs\n\n\n# Generate centers for the blobs so that it forms a 10 X 10 grid.\nxx = np.linspace(-22, 22, 10)\nyy = np.linspace(-22, 22, 10)\nxx, yy = np.meshgrid(xx, yy)\nn_centers = np.hstack((np.ravel(xx)[:, np.newaxis], np.ravel(yy)[:, np.newaxis]))\n\n# Generate blobs to do a comparison between MiniBatchKMeans and BIRCH.\nX, y = make_blobs(n_samples=25000, centers=n_centers, random_state=0)\n\n# Use all colors that matplotlib provides by default.\ncolors_ = cycle(colors.cnames.keys())\n\nfig = plt.figure(figsize=(12, 4))\nfig.subplots_adjust(left=0.04, right=0.98, bottom=0.1, top=0.9)\n\n# Compute clustering with BIRCH with and without the final clustering step\n# and plot.\nbirch_models = [\n Birch(threshold=1.7, n_clusters=None),\n Birch(threshold=1.7, n_clusters=100),\n]\nfinal_step = [\"without global clustering\", \"with global clustering\"]\n\nfor ind, (birch_model, info) in enumerate(zip(birch_models, final_step)):\n t = time()\n birch_model.fit(X)\n print(\"BIRCH %s as the final step took %0.2f seconds\" % (info, (time() - t)))\n\n # Plot result\n labels = birch_model.labels_\n centroids = birch_model.subcluster_centers_\n n_clusters = np.unique(labels).size\n print(\"n_clusters : %d\" % n_clusters)\n\n ax = fig.add_subplot(1, 3, ind + 1)\n for this_centroid, k, col in zip(centroids, range(n_clusters), colors_):\n mask = labels == k\n ax.scatter(X[mask, 0], X[mask, 1], c=\"w\", edgecolor=col, marker=\".\", alpha=0.5)\n if birch_model.n_clusters is None:\n ax.scatter(this_centroid[0], this_centroid[1], marker=\"+\", c=\"k\", s=25)\n ax.set_ylim([-25, 25])\n ax.set_xlim([-25, 25])\n ax.set_autoscaley_on(False)\n ax.set_title(\"BIRCH %s\" % info)\n\n# Compute clustering with MiniBatchKMeans.\nmbk = MiniBatchKMeans(\n init=\"k-means++\",\n n_clusters=100,\n batch_size=256 * cpu_count(),\n n_init=10,\n max_no_improvement=10,\n verbose=0,\n random_state=0,\n)\nt0 = time()\nmbk.fit(X)\nt_mini_batch = time() - t0\nprint(\"Time taken to run MiniBatchKMeans %0.2f seconds\" % t_mini_batch)\nmbk_means_labels_unique = np.unique(mbk.labels_)\n\nax = fig.add_subplot(1, 3, 3)\nfor this_centroid, k, col in zip(mbk.cluster_centers_, range(n_clusters), colors_):\n mask = mbk.labels_ == k\n ax.scatter(X[mask, 0], X[mask, 1], marker=\".\", c=\"w\", edgecolor=col, alpha=0.5)\n ax.scatter(this_centroid[0], this_centroid[1], marker=\"+\", c=\"k\", s=25)\nax.set_xlim([-25, 25])\nax.set_ylim([-25, 25])\nax.set_title(\"MiniBatchKMeans\")\nax.set_autoscaley_on(False)\nplt.show()"
3030
]
3131
}
3232
],

dev/_downloads/e3c29fcee17ffb4a67e11b147b8a86bb/plot_birch_vs_minibatchkmeans.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
for ind, (birch_model, info) in enumerate(zip(birch_models, final_step)):
6363
t = time()
6464
birch_model.fit(X)
65-
time_ = time() - t
6665
print("BIRCH %s as the final step took %0.2f seconds" % (info, (time() - t)))
6766

6867
# Plot result

dev/_downloads/scikit-learn-docs.zip

5.69 KB
Binary file not shown.
-212 Bytes
142 Bytes
-48 Bytes
-32 Bytes
-62 Bytes

0 commit comments

Comments
 (0)