python函一维聚类_无监督学习聚类一维阵列

试试^{}。根据均值漂移的skleanuser guide:The algorithm automatically sets the number of clusters, ...

修改后的演示代码:import numpy as np

from sklearn.cluster import MeanShift, estimate_bandwidth

# #############################################################################

# Generate sample data

X = [1,2,4,7,9,5,4,7,9,56,57,54,60,200,297,275,243]

X = np.reshape(X, (-1, 1))

# #############################################################################

# Compute clustering with MeanShift

# The following bandwidth can be automatically detected using

# bandwidth = estimate_bandwidth(X, quantile=0.2, n_samples=100)

ms = MeanShift(bandwidth=None, bin_seeding=True)

ms.fit(X)

labels = ms.labels_

cluster_centers = ms.cluster_centers_

labels_unique = np.unique(labels)

n_clusters_ = len(labels_unique)

print("number of estimated clusters : %d" % n_clusters_)

print(labels)

输出:

^{pr2}$

请注意,MeanShift是可伸缩的,可随样本数量而变化。建议上限为10000。在

顺便说一句,正如rahlf23所提到的,K-mean是一种无监督的学习算法。您必须指定集群的数量并不意味着它是受监控的。在

另请参见:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值