forked from scikit-learn/scikit-learn.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsklearn.cluster.k_means.html
380 lines (345 loc) · 16.1 KB
/
sklearn.cluster.k_means.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>sklearn.cluster.k_means — scikit-learn 0.20.dev0 documentation</title>
<!-- htmltitle is before nature.css - we use this hack to load bootstrap first -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../../_static/css/bootstrap.min.css" media="screen" />
<link rel="stylesheet" href="../../_static/css/bootstrap-responsive.css"/>
<link rel="stylesheet" href="../../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/gallery.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: '0.20.dev0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<script type="text/javascript" src="../../_static/js/copybutton.js"></script>
<script type="text/javascript" src="../../_static/js/extra.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_SVG"></script>
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<link rel="author" title="About these documents" href="../../about.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="sklearn.cluster.mean_shift" href="sklearn.cluster.mean_shift.html" />
<link rel="prev" title="sklearn.cluster.estimate_bandwidth" href="sklearn.cluster.estimate_bandwidth.html" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="../../_static/js/bootstrap.min.js" type="text/javascript"></script>
<script>
VERSION_SUBDIR = (function(groups) {
return groups ? groups[1] : null;
})(location.href.match(/^https?:\/\/scikit-learn.org\/([^\/]+)/));
</script>
<link rel="canonical" href="http://scikit-learn.org/stable/modules/generated/sklearn.cluster.k_means.html" />
<script type="text/javascript">
$("div.buttonNext, div.buttonPrevious").hover(
function () {
$(this).css('background-color', '#FF9C34');
},
function () {
$(this).css('background-color', '#A7D6E2');
}
);
function showMenu() {
var topNav = document.getElementById("scikit-navbar");
if (topNav.className === "navbar") {
topNav.className += " responsive";
} else {
topNav.className = "navbar";
}
};
</script>
</head>
<body>
<div class="header-wrapper">
<div class="header">
<p class="logo"><a href="../../index.html">
<img src="../../_static/scikit-learn-logo-small.png" alt="Logo"/>
</a>
</p><div class="navbar" id="scikit-navbar">
<ul>
<li><a href="../../index.html">Home</a></li>
<li><a href="../../install.html">Installation</a></li>
<li class="btn-li"><div class="btn-group">
<a href="../../documentation.html">Documentation</a>
<a class="btn dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li class="link-title">Scikit-learn <script>document.write(DOCUMENTATION_OPTIONS.VERSION + (VERSION_SUBDIR ? " (" + VERSION_SUBDIR + ")" : ""));</script></li>
<li><a href="../../tutorial/index.html">Tutorials</a></li>
<li><a href="../../user_guide.html">User guide</a></li>
<li><a href="../classes.html">API</a></li>
<li><a href="../../glossary.html">Glossary</a></li>
<li><a href="../../faq.html">FAQ</a></li>
<li><a href="../../developers/contributing.html">Contributing</a></li>
<li class="divider"></li>
<script>if (VERSION_SUBDIR != "stable") document.write('<li><a href="http://scikit-learn.org/stable/documentation.html">Stable version</a></li>')</script>
<script>if (VERSION_SUBDIR != "dev") document.write('<li><a href="http://scikit-learn.org/dev/documentation.html">Development version</a></li>')</script>
<li><a href="http://scikit-learn.org/dev/versions.html">All available versions</a></li>
<li><a href="../../_downloads/scikit-learn-docs.pdf">PDF documentation</a></li>
</ul>
</div>
</li>
<li><a href="../../auto_examples/index.html">Examples</a></li>
</ul>
<a href="javascript:void(0);" onclick="showMenu()">
<div class="nav-icon">
<div class="hamburger-line"></div>
<div class="hamburger-line"></div>
<div class="hamburger-line"></div>
</div>
</a>
<div class="search_form">
<div class="gcse-search" id="cse" style="width: 100%;"></div>
</div>
</div> <!-- end navbar --></div>
</div>
<!-- GitHub "fork me" ribbon -->
<a href="https://github.com/scikit-learn/scikit-learn">
<img class="fork-me"
style="position: absolute; top: 0; right: 0; border: 0;"
src="../../_static/img/forkme.png"
alt="Fork me on GitHub" />
</a>
<div class="content-wrapper">
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div class="rel">
<div class="rellink">
<a href="sklearn.cluster.estimate_bandwidth.html"
accesskey="P">Previous
<br/>
<span class="smallrellink">
sklearn.clust...
</span>
<span class="hiddenrellink">
sklearn.cluster.estimate_bandwidth
</span>
</a>
</div>
<div class="spacer">
</div>
<div class="rellink">
<a href="sklearn.cluster.mean_shift.html"
accesskey="N">Next
<br/>
<span class="smallrellink">
sklearn.clust...
</span>
<span class="hiddenrellink">
sklearn.cluster.mean_shift
</span>
</a>
</div>
<!-- Ad a link to the 'up' page -->
<div class="spacer">
</div>
<div class="rellink">
<a href="../classes.html">
Up
<br/>
<span class="smallrellink">
API Reference
</span>
<span class="hiddenrellink">
API Reference
</span>
</a>
</div>
</div>
<p class="doc-version"><b>scikit-learn v0.20.dev0</b><br/>
<a href="http://scikit-learn.org/stable/support.html#documentation-resources">Other versions</a></p>
<p class="citing">Please <b><a href="../../about.html#citing-scikit-learn" style="font-size: 110%;">cite us </a></b>if you use the software.</p>
<ul>
<li><a class="reference internal" href="#"><code class="docutils literal"><span class="pre">sklearn.cluster</span></code>.k_means</a></li>
</ul>
</div>
</div>
<input type="checkbox" id="nav-trigger" class="nav-trigger" checked />
<label for="nav-trigger"></label>
<div class="content">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="sklearn-cluster-k-means">
<h1><a class="reference internal" href="../classes.html#module-sklearn.cluster" title="sklearn.cluster"><code class="xref py py-mod docutils literal"><span class="pre">sklearn.cluster</span></code></a>.k_means<a class="headerlink" href="#sklearn-cluster-k-means" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="sklearn.cluster.k_means">
<code class="descclassname">sklearn.cluster.</code><code class="descname">k_means</code><span class="sig-paren">(</span><em>X</em>, <em>n_clusters</em>, <em>sample_weight=None</em>, <em>init='k-means++'</em>, <em>precompute_distances='auto'</em>, <em>n_init=10</em>, <em>max_iter=300</em>, <em>verbose=False</em>, <em>tol=0.0001</em>, <em>random_state=None</em>, <em>copy_x=True</em>, <em>n_jobs=1</em>, <em>algorithm='auto'</em>, <em>return_n_iter=False</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/474b5e0/sklearn/cluster/k_means_.py#L185"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.cluster.k_means" title="Permalink to this definition">¶</a></dt>
<dd><p>K-means clustering algorithm.</p>
<p>Read more in the <a class="reference internal" href="../clustering.html#k-means"><span class="std std-ref">User Guide</span></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><p class="first"><strong>X</strong> : array-like or sparse matrix, shape (n_samples, n_features)</p>
<blockquote>
<div><p>The observations to cluster. It must be noted that the data
will be converted to C ordering, which will cause a memory copy
if the given data is not C-contiguous.</p>
</div></blockquote>
<p><strong>n_clusters</strong> : int</p>
<blockquote>
<div><p>The number of clusters to form as well as the number of
centroids to generate.</p>
</div></blockquote>
<p><strong>sample_weight</strong> : array-like, shape (n_samples,), optional</p>
<blockquote>
<div><p>The weights for each observation in X. If None, all observations
are assigned equal weight (default: None)</p>
</div></blockquote>
<p><strong>init</strong> : {‘k-means++’, ‘random’, or ndarray, or a callable}, optional</p>
<blockquote>
<div><p>Method for initialization, default to ‘k-means++’:</p>
<p>‘k-means++’ : selects initial cluster centers for k-mean
clustering in a smart way to speed up convergence. See section
Notes in k_init for more details.</p>
<p>‘random’: choose k observations (rows) at random from data for
the initial centroids.</p>
<p>If an ndarray is passed, it should be of shape (n_clusters, n_features)
and gives the initial centers.</p>
<p>If a callable is passed, it should take arguments X, k and
and a random state and return an initialization.</p>
</div></blockquote>
<p><strong>precompute_distances</strong> : {‘auto’, True, False}</p>
<blockquote>
<div><p>Precompute distances (faster but takes more memory).</p>
<p>‘auto’ : do not precompute distances if n_samples * n_clusters > 12
million. This corresponds to about 100MB overhead per job using
double precision.</p>
<p>True : always precompute distances</p>
<p>False : never precompute distances</p>
</div></blockquote>
<p><strong>n_init</strong> : int, optional, default: 10</p>
<blockquote>
<div><p>Number of time the k-means algorithm will be run with different
centroid seeds. The final results will be the best output of
n_init consecutive runs in terms of inertia.</p>
</div></blockquote>
<p><strong>max_iter</strong> : int, optional, default 300</p>
<blockquote>
<div><p>Maximum number of iterations of the k-means algorithm to run.</p>
</div></blockquote>
<p><strong>verbose</strong> : boolean, optional</p>
<blockquote>
<div><p>Verbosity mode.</p>
</div></blockquote>
<p><strong>tol</strong> : float, optional</p>
<blockquote>
<div><p>The relative increment in the results before declaring convergence.</p>
</div></blockquote>
<p><strong>random_state</strong> : int, RandomState instance or None (default)</p>
<blockquote>
<div><p>Determines random number generation for centroid initialization. Use
an int to make the randomness deterministic.
See <a class="reference internal" href="../../glossary.html#term-random-state"><span class="xref std std-term">Glossary</span></a>.</p>
</div></blockquote>
<p><strong>copy_x</strong> : boolean, optional</p>
<blockquote>
<div><p>When pre-computing distances it is more numerically accurate to center
the data first. If copy_x is True (default), then the original data is
not modified, ensuring X is C-contiguous. If False, the original data
is modified, and put back before the function returns, but small
numerical differences may be introduced by subtracting and then adding
the data mean, in this case it will also not ensure that data is
C-contiguous which may cause a significant slowdown.</p>
</div></blockquote>
<p><strong>n_jobs</strong> : int</p>
<blockquote>
<div><p>The number of jobs to use for the computation. This works by computing
each of the n_init runs in parallel.</p>
<p>If -1 all CPUs are used. If 1 is given, no parallel computing code is
used at all, which is useful for debugging. For n_jobs below -1,
(n_cpus + 1 + n_jobs) are used. Thus for n_jobs = -2, all CPUs but one
are used.</p>
</div></blockquote>
<p><strong>algorithm</strong> : “auto”, “full” or “elkan”, default=”auto”</p>
<blockquote>
<div><p>K-means algorithm to use. The classical EM-style algorithm is “full”.
The “elkan” variation is more efficient by using the triangle
inequality, but currently doesn’t support sparse data. “auto” chooses
“elkan” for dense data and “full” for sparse data.</p>
</div></blockquote>
<p><strong>return_n_iter</strong> : bool, optional</p>
<blockquote>
<div><p>Whether or not to return the number of iterations.</p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>centroid</strong> : float ndarray with shape (k, n_features)</p>
<blockquote>
<div><p>Centroids found at the last iteration of k-means.</p>
</div></blockquote>
<p><strong>label</strong> : integer ndarray with shape (n_samples,)</p>
<blockquote>
<div><p>label[i] is the code or index of the centroid the
i’th observation is closest to.</p>
</div></blockquote>
<p><strong>inertia</strong> : float</p>
<blockquote>
<div><p>The final value of the inertia criterion (sum of squared distances to
the closest centroid for all observations in the training set).</p>
</div></blockquote>
<p><strong>best_n_iter</strong> : int</p>
<blockquote class="last">
<div><p>Number of iterations corresponding to the best results.
Returned only if <cite>return_n_iter</cite> is set to True.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<div class="clearer"></div></div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
<div class="footer">
© 2007 - 2018, scikit-learn developers (BSD License).
<a href="../../_sources/modules/generated/sklearn.cluster.k_means.rst.txt" rel="nofollow">Show this page source</a>
</div>
<div class="rel">
<div class="buttonPrevious">
<a href="sklearn.cluster.estimate_bandwidth.html">Previous
</a>
</div>
<div class="buttonNext">
<a href="sklearn.cluster.mean_shift.html">Next
</a>
</div>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22606712-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script>
(function() {
var cx = '016639176250731907682:tjtqbvtvij0';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>
</body>
</html>