我正在使用sklearn.mixture
的Gaussian Mixture Model (GMM)来执行我的数据集的聚类。Python集群'纯度'度量
我可以使用函数score()
来计算模型下的对数概率。
但是,我正在寻找一种称为'纯度'的度量标准,它在中定义。
我该如何在Python中实现它?我当前的实现看起来是这样的:
from sklearn.mixture import GMM
# X is a 1000 x 2 array (1000 samples of 2 coordinates).
# It is actually a 2 dimensional PCA projection of data
# extracted from the MNIST dataset, but this random array
# is equivalent as far as the code is concerned.
X = np.random.rand(1000, 2)
clusterer = GMM(3, 'diag')
clusterer.fit(X)
cluster_labels = clusterer.predict(X)
# Now I can count the labels for each cluster..
count0 = list(cluster_labels).count(0)
count1 = list(cluster_labels).count(1)
count2 = list(cluster_labels).count(2)
但我可以通过每个集群,以计算混淆矩阵不是循环(根据本question)
该论文是相当不透明。 [这个答案](http://stats.stackexchange.com/a/154379/89612)上的交叉验证简化了一下程序。 – kdbanman
请发布您到目前为止的代码,并告诉我们所涉及的数据结构。 – kdbanman
目前,我的代码是: '从sklearn.mixture进口GMM 人聚类= GMM(5 '诊断') clusterer.fit(X) cluster_labels = clusterer.predict(X)' 我看到,在为了计算纯度我需要混淆矩阵。现在,我的问题是,我无法遍历每个群集,并计算每个类别分为多少个对象。 – Kuka