【发布时间】:2018-01-16 06:13:24
【问题描述】:
我正在 Python 中对一组文本数据执行文本聚类。基本上,我使用 tf idf score,然后将结果矩阵应用到 kmeans 算法中,就像这样:
vect = TfidfVectorizer(min_df=100,stop_words=sw)
dtm = vect.fit_transform(df)
l=vect.get_feature_names()
k = 15
model = MiniBatchKMeans(n_clusters=k)
model.fit(dtm)
order_centroids = model.cluster_centers_.argsort()[:, ::-1]
terms = vect.get_feature_names()
for i in range(k):
print("Cluster %d:" % i, end='')
for ind in order_centroids[i, :100]:
print(' %s' % l[ind], end='')
print()
然后在执行以下操作后,我得到了 15 个相同的集群(其中包含几乎完全相同的词项)。我也尝试使用 LSA 方法进行归一化,但结果几乎相同。
我做错了什么以及如何解决?
【问题讨论】:
-
可以上传数据吗?您还使用什么版本的 sklearn?
标签: python scikit-learn nlp nltk tf-idf