如何在 sklearn.cluster.MeanShift 中获取特定簇的中心
How to get the center of specific cluster in sklearn.cluster.MeanShift
我有一个经过训练的 MeanShift 对象 (ms
)。它有一个简单的中心列表。如何确定一个中心所属的标签?
我知道 labels_
,但我没有看到 labels_
和 cluster_centers_
之间的联系。
print(ms.cluster_centers_)
[[ 40.7177164 -73.99183542]
[ 33.44943805 -112.00213969]
[ 33.44638027 -111.90188756]
...,
[ 46.7323875 -117.0001651 ]
[ 29.6899563 -95.8996757 ]
[ 31.3787916 -95.3213317 ]]
labels
的维度是你的原始数据集的维度。它给出了相应簇的索引。因此,原始数据中条目 i
的关联聚类中心是 cluster_centers_[labels_[i]]
.
您可以在 sklearn 的示例中看到,它们正在循环处理唯一标签的数量,并使用 labels == k
到 select 具有该标签的所有数据 (X[labels_ == k]
) :
https://scikit-learn.org/stable/auto_examples/cluster/plot_mean_shift.html#sphx-glr-auto-examples-cluster-plot-mean-shift-py
我有一个经过训练的 MeanShift 对象 (ms
)。它有一个简单的中心列表。如何确定一个中心所属的标签?
我知道 labels_
,但我没有看到 labels_
和 cluster_centers_
之间的联系。
print(ms.cluster_centers_)
[[ 40.7177164 -73.99183542]
[ 33.44943805 -112.00213969]
[ 33.44638027 -111.90188756]
...,
[ 46.7323875 -117.0001651 ]
[ 29.6899563 -95.8996757 ]
[ 31.3787916 -95.3213317 ]]
labels
的维度是你的原始数据集的维度。它给出了相应簇的索引。因此,原始数据中条目 i
的关联聚类中心是 cluster_centers_[labels_[i]]
.
您可以在 sklearn 的示例中看到,它们正在循环处理唯一标签的数量,并使用 labels == k
到 select 具有该标签的所有数据 (X[labels_ == k]
) :
https://scikit-learn.org/stable/auto_examples/cluster/plot_mean_shift.html#sphx-glr-auto-examples-cluster-plot-mean-shift-py