我想计算使用KMeans生成的集群之间的相似性,使用Jaccard索引(来自sklearn.metrics import jaccard_similarity_score)。这些可以是包含特定值的矩阵:at [i,j]应该是簇i和j之间的相似性。我现在的代码:
from sklearn import datasets
from sklearn.cluster import KMeans
from sklearn.metrics import jaccard_similarity_score
iris = datasets.load_iris()
X = iris.data
kmeans = KMeans(n_clusters=3).fit(X)
labels = kmeans.labels_
for i in range(3):
for j in range(3):
print(jaccard_similarity_score(X[np.where(labels==i)], X[np.where(labels==j)]))
但我有以下错误:
Traceback (most recent call last):
File "<ipython-input-15-e7b8e4471987>", line 3, in <module>
print(jaccard_similarity_score(X[np.where(labels==i)], X[np.where(labels==j)]))
File "C:\Anaconda3\envs\p3\lib\site-packages\sklearn\metrics\classification.py", line 383, in jaccard_similarity_score
y_type, y_true, y_pred = _check_targets(y_true, y_pred)
File "C:\Anaconda3\envs\p3\lib\site-packages\sklearn\metrics\classification.py", line 89, in _check_targets
raise ValueError("{0} is not supported".format(y_type))
ValueError: continuous-multioutput is not supported
答案 0 :(得分:0)
Jaccard在集上定义。
K-means生成连续质心(因为它使用 mean ,字面意思)。
因此,您无法在群集中心使用Jaccard。