kmeans python自定义初始聚类中心_scikit学习kmeans聚类的初始质心

是的,通过init设置初始质心应该可以工作。以下是scikit learndocumentation的一段引述:init : {‘k-means++’, ‘random’ or an ndarray}

Method for initialization, defaults to ‘k-means++’:

If an ndarray is passed, it should be of shape (n_clusters, n_features)

and gives the initial centers.What is the shape (n_clusters, n_features) referring to?

形状要求意味着init必须正好有n_clusters行,并且每行中的元素数应与actual_data_points的维度匹配:>>> init = np.array([[-0.12, 0.939, 0.321, 0.011],

[0.0, 0.874, -0.486, 0.862],

[0.0, 1.0, 0.0, 0.033],

[0.12, 0.939, 0.321, -0.7],

[0.0, 1.0, 0.0, -0.203],

[0.12, 0.939, -0.321, 0.25],

[0.0, 0.874, 0.486, -0.575],

[-0.12, 0.939, -0.321, 0.961]],

np.float64)

>>> init.shape[0] == 8

True # n_clusters

>>> init.shape[1] == actual_data_points.shape[1]

True # n_featuresWhat is n_features?

n_features是样本的维数。例如,如果要在二维平面上聚集点,n_features将是2。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值