当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python sklearn kmeans_plusplus用法及代码示例


本文简要介绍python语言中 sklearn.cluster.kmeans_plusplus 的用法。

用法:

sklearn.cluster.kmeans_plusplus(X, n_clusters, *, x_squared_norms=None, random_state=None, n_local_trials=None)

根据k-means++初始化n_clusters种子

参数

X{类数组,稀疏矩阵},形状为 (n_samples, n_features)

从中挑选种子的数据。

n_clustersint

要初始化的质心数

x_squared_norms形状类似数组 (n_samples,),默认=None

每个数据点的平方欧几里得范数。

random_stateint 或 RandomState 实例,默认=无

确定质心初始化的随机数生成。传递 int 以在多个函数调用之间实现可重现的输出。请参阅术语表。

n_local_trials整数,默认=无

每个中心的播种试验次数(第一次除外),其中最减少惯性的一个被贪心地选择。设置为 None 使试验次数与种子数成对数关系 (2+log(k))。

返回

centersndarray 形状(n_clusters,n_features)

k-means 的初始中心。

indicesndarray 形状 (n_clusters,)

数据数组 X 中所选中心的索引位置。对于给定的索引和中心,X[index] = center。

注意

以智能方式为k-mean 聚类选择初始聚类中心以加速收敛。参见:Arthur, D. 和 Vassilvitskii, S. “k-means++:仔细播种的优势”。 ACM-SIAM 离散算法研讨会。 2007年

例子

>>> from sklearn.cluster import kmeans_plusplus
>>> import numpy as np
>>> X = np.array([[1, 2], [1, 4], [1, 0],
...               [10, 2], [10, 4], [10, 0]])
>>> centers, indices = kmeans_plusplus(X, n_clusters=2, random_state=0)
>>> centers
array([[10,  4],
       [ 1,  0]])
>>> indices
array([4, 2])

相关用法


注:本文由纯净天空筛选整理自scikit-learn.org大神的英文原创作品 sklearn.cluster.kmeans_plusplus。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。