@@ -269,7 +269,7 @@ def k_means(
269
269
algorithm = "auto" ,
270
270
return_n_iter = False ,
271
271
):
272
- """K-means clustering algorithm.
272
+ """Perform K-means clustering algorithm.
273
273
274
274
Read more in the :ref:`User Guide <k_means>`.
275
275
@@ -285,30 +285,27 @@ def k_means(
285
285
centroids to generate.
286
286
287
287
sample_weight : array-like of shape (n_samples,), default=None
288
- The weights for each observation in X . If None, all observations
288
+ The weights for each observation in `X` . If ` None` , all observations
289
289
are assigned equal weight.
290
290
291
291
init : {'k-means++', 'random'}, callable or array-like of shape \
292
292
(n_clusters, n_features), default='k-means++'
293
293
Method for initialization:
294
294
295
- 'k-means++' : selects initial cluster centers for k-mean
296
- clustering in a smart way to speed up convergence. See section
297
- Notes in k_init for more details.
298
-
299
- 'random': choose `n_clusters` observations (rows) at random from data
300
- for the initial centroids.
301
-
302
- If an array is passed, it should be of shape (n_clusters, n_features)
303
- and gives the initial centers.
304
-
305
- If a callable is passed, it should take arguments X, n_clusters and a
306
- random state and return an initialization.
295
+ - `'k-means++'` : selects initial cluster centers for k-mean
296
+ clustering in a smart way to speed up convergence. See section
297
+ Notes in k_init for more details.
298
+ - `'random'`: choose `n_clusters` observations (rows) at random from data
299
+ for the initial centroids.
300
+ - If an array is passed, it should be of shape `(n_clusters, n_features)`
301
+ and gives the initial centers.
302
+ - If a callable is passed, it should take arguments `X`, `n_clusters` and a
303
+ random state and return an initialization.
307
304
308
305
n_init : int, default=10
309
306
Number of time the k-means algorithm will be run with different
310
307
centroid seeds. The final results will be the best output of
311
- n_init consecutive runs in terms of inertia.
308
+ ` n_init` consecutive runs in terms of inertia.
312
309
313
310
max_iter : int, default=300
314
311
Maximum number of iterations of the k-means algorithm to run.
@@ -328,22 +325,22 @@ def k_means(
328
325
329
326
copy_x : bool, default=True
330
327
When pre-computing distances it is more numerically accurate to center
331
- the data first. If copy_x is True (default), then the original data is
328
+ the data first. If ` copy_x` is True (default), then the original data is
332
329
not modified. If False, the original data is modified, and put back
333
330
before the function returns, but small numerical differences may be
334
331
introduced by subtracting and then adding the data mean. Note that if
335
332
the original data is not C-contiguous, a copy will be made even if
336
- copy_x is False. If the original data is sparse, but not in CSR format,
337
- a copy will be made even if copy_x is False.
333
+ ` copy_x` is False. If the original data is sparse, but not in CSR format,
334
+ a copy will be made even if ` copy_x` is False.
338
335
339
336
algorithm : {"auto", "full", "elkan"}, default="auto"
340
- K-means algorithm to use. The classical EM-style algorithm is "full".
341
- The "elkan" variation is more efficient on data with well-defined
337
+ K-means algorithm to use. The classical EM-style algorithm is ` "full"` .
338
+ The ` "elkan"` variation is more efficient on data with well-defined
342
339
clusters, by using the triangle inequality. However it's more memory
343
340
intensive due to the allocation of an extra array of shape
344
- (n_samples, n_clusters).
341
+ ` (n_samples, n_clusters)` .
345
342
346
- For now "auto" (kept for backward compatibility) chooses "elkan" but it
343
+ For now ` "auto"` (kept for backward compatibility) chooses ` "elkan"` but it
347
344
might change in the future for a better heuristic.
348
345
349
346
return_n_iter : bool, default=False
@@ -355,7 +352,7 @@ def k_means(
355
352
Centroids found at the last iteration of k-means.
356
353
357
354
label : ndarray of shape (n_samples,)
358
- label[i] is the code or index of the centroid the
355
+ The ` label[i]` is the code or index of the centroid the
359
356
i'th observation is closest to.
360
357
361
358
inertia : float
0 commit comments