Skip to content

Commit b079285

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 11f97429929568e3061997e9cd878086edccb27f
1 parent 90b963b commit b079285

File tree

1,222 files changed

+5310
-4201
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,222 files changed

+5310
-4201
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n# An example of K-Means++ initialization\n\nAn example to show the output of the :func:`sklearn.cluster.kmeans_plusplus`\nfunction for generating initial seeds for clustering.\n\nK-Means++ is used as the default initialization for `k_means`.\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"print(__doc__)\n\nfrom sklearn.cluster import kmeans_plusplus\nfrom sklearn.datasets import make_blobs\nimport matplotlib.pyplot as plt\n\n# Generate sample data\nn_samples = 4000\nn_components = 4\n\nX, y_true = make_blobs(n_samples=n_samples,\n centers=n_components,\n cluster_std=0.60,\n random_state=0)\nX = X[:, ::-1]\n\n# Calculate seeds from kmeans++\ncenters_init, indices = kmeans_plusplus(X, n_clusters=4,\n random_state=0)\n\n# Plot init seeds along side sample data\nplt.figure(1)\ncolors = ['#4EACC5', '#FF9C34', '#4E9A06', 'm']\n\nfor k, col in enumerate(colors):\n cluster_data = y_true == k\n plt.scatter(X[cluster_data, 0], X[cluster_data, 1],\n c=col, marker='.', s=10)\n\nplt.scatter(centers_init[:, 0], centers_init[:, 1], c='b', s=50)\nplt.title(\"K-Means++ Initialization\")\nplt.xticks([])\nplt.yticks([])\nplt.show()"
30+
]
31+
}
32+
],
33+
"metadata": {
34+
"kernelspec": {
35+
"display_name": "Python 3",
36+
"language": "python",
37+
"name": "python3"
38+
},
39+
"language_info": {
40+
"codemirror_mode": {
41+
"name": "ipython",
42+
"version": 3
43+
},
44+
"file_extension": ".py",
45+
"mimetype": "text/x-python",
46+
"name": "python",
47+
"nbconvert_exporter": "python",
48+
"pygments_lexer": "ipython3",
49+
"version": "3.8.5"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
===========================================================
3+
An example of K-Means++ initialization
4+
===========================================================
5+
6+
An example to show the output of the :func:`sklearn.cluster.kmeans_plusplus`
7+
function for generating initial seeds for clustering.
8+
9+
K-Means++ is used as the default initialization for :ref:`k_means`.
10+
11+
"""
12+
print(__doc__)
13+
14+
from sklearn.cluster import kmeans_plusplus
15+
from sklearn.datasets import make_blobs
16+
import matplotlib.pyplot as plt
17+
18+
# Generate sample data
19+
n_samples = 4000
20+
n_components = 4
21+
22+
X, y_true = make_blobs(n_samples=n_samples,
23+
centers=n_components,
24+
cluster_std=0.60,
25+
random_state=0)
26+
X = X[:, ::-1]
27+
28+
# Calculate seeds from kmeans++
29+
centers_init, indices = kmeans_plusplus(X, n_clusters=4,
30+
random_state=0)
31+
32+
# Plot init seeds along side sample data
33+
plt.figure(1)
34+
colors = ['#4EACC5', '#FF9C34', '#4E9A06', 'm']
35+
36+
for k, col in enumerate(colors):
37+
cluster_data = y_true == k
38+
plt.scatter(X[cluster_data, 0], X[cluster_data, 1],
39+
c=col, marker='.', s=10)
40+
41+
plt.scatter(centers_init[:, 0], centers_init[:, 1], c='b', s=50)
42+
plt.title("K-Means++ Initialization")
43+
plt.xticks([])
44+
plt.yticks([])
45+
plt.show()

dev/_downloads/scikit-learn-docs.pdf

55.5 KB
Binary file not shown.

dev/_images/binder_badge_logo.png

0 Bytes

dev/_images/iris.png

0 Bytes
252 Bytes
252 Bytes
297 Bytes

0 commit comments

Comments
 (0)