【问题标题】:Identical Clusters after Text Clustering in PythonPython中文本聚类后的相同聚类
【发布时间】: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


【解决方案1】:

我的猜测是您的特征没有标准化,这意味着dtm 中的某些列包含的分布集中在比其他列更高的平均值附近。因此,您用于提取与集群相关的特征的排序将错误地偏爱这些特征。

避免此类问题的常见做法是将您的功能standardize 发送到zero meanunit variance,如下所示:

dtm_standardized = (dtm - dtm.mean(axis=0)) / dtm.std(axis=0)

或者像这样:

dtm_standardized = sklearn.preprocessing.scale(dtm)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-28
    • 2010-12-19
    • 2016-08-14
    • 1970-01-01
    • 2015-04-27
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多