如何理解 Kmean 的簇?

How to give sense to clusters of Kmean?

您好,我正在使用 Kmeans 构建主题 classifier,我的想法是将来自不同用户的几条 Facebook 评论获取多个文档。

我的文档列表如下所示:

list=["comment1","comment2",...,"commentN"]

然后我使用 tfidf 对每个评论进行矢量化并将其分配给特定的集群, 我的程序的输出如下:

tfidf = tfidf_vectorizer.fit_transform(list)
tf = tf_vectorizer.fit_transform(list)    
print("size of tf",tf.shape)
print("size of tfidf",tfidf.shape)   
#Creating clusters from data
kmeans = KMeans(n_clusters=8, random_state=0).fit(tf)   
print("printing labels",kmeans.labels_)    
#Printing the number of clusters 
print("Number of clusters",set(kmeans.labels_))
print("dimensions of matrix labels",(kmeans.labels_).shape)
#Predicting new labels
y_pred = kmeans.predict(tf)
print("dimensions of predict matrix",y_pred.shape)

我的输出如下所示:

size of tf (202450, 2000)
size of tfidf (202450, 2000)
printing labels [1 1 1 ..., 1 1 1]
Number of clusters {0, 1, 2, 3, 4, 5, 6, 7}
dimensions of matrix labels (202450,)
dimensions of predict matrix (202450,)
C:\Program Files\Anaconda3\lib\site-packages\sklearn\utils\validation.py:420: DataConversionWarning: Data with input dtype int64 was converted to float64.
  warnings.warn(msg, DataConversionWarning)

现在的问题是我想找到一种方法来理解这个集群我的意思是 class 0 是关于体育的,class 1 是关于政治的,所以我会喜欢欣赏任何建议来理解这个集群,或者至少找到一种方法来获取属于特定集群的所有评论,然后解释这个结果感谢支持。

有多种方法

最简单的方法是获取每个聚类的质心,这是对聚类中使用的大多数单词的一个很好的总结。

第二种方法是获取分配给每个簇的元素的tf-idf子矩阵, 之后就可以在子矩阵上使用ACP提取因子,更加了解每个簇的组成。

抱歉,我没有使用sckit-learn,所以无法通过代码帮助您

希望能有所帮助