python - 如何计算 scikit-learn 中输出值的出现次数?
问题描述
我有数据(d),一个片段如下所示:
[[2123, 324, 234, 324, 534, 6435], [43543, 45345, 353, 5345, 543, 5435],..., n]
from sklearn.cluster import KMeans
kmean=KMeans(n_clusters=3)
kmean.fit(d)
# Returns an array of either 0, 1 or 2, where each of these values is the cluster
# that an element has been assigned to. Example found below.
kmean.labels_
出去:
array([0, 1,..., n])
即第一个列表[2123, 324, 234, 324, 534, 6435]
对应于集群 0,第二个列表[43543, 45345, 353, 5345, 543, 5435]
对应于集群 1。
问题:如何确定分配给每个集群值的元素(列表)的数量?
我试图len(kmean.labels_[0])
找到例如 0 的元素的数量,但这没有用。有什么建议么?
解决方案
您可以使用np.bincount(kmean.labels_)
推荐阅读
- r - 构建向量的所有组合 - 寻找更好的方法
- java - 编译最新版本的l2switch时出现问题
- ios - Swift NSCoder 不适用于双变量
- java - Java 等价于 C++ 箭头
- sqlite - SQLite如何处理最后带有负号的负数
- javascript - FeatureCollection 中的“crs”是什么意思?
- javascript - firebase 实时数据库,如果用户是对话的一部分,则 child_changed
- ios - iOS:应用 API KEY 限制时 Google Maps API 失败
- excel - Excel - 查找第二高块平均值
- javascript - JavaScript 性能:对于大量不变的数据,使用对象变量还是 AJAX 请求更好?