【发布时间】:2016-12-18 06:38:01
【问题描述】:
sample=['he buy fish','he buy bread','the pizza is die'
,'the man buy pizza','mcdonald is there','there is a boy',
'who beat the man','burger and pizza']
fidf_vectorizer = TfidfVectorizer(max_df=0.8, max_features=200000, min_df=0.2, stop_words='english',use_idf=True)
vect=TfidfVectorizer(min_df=1)
x=vect.fit_transform(sample)
idf=vect.idf_
dist = 1 - cosine_similarity(x)
num_clusters = 3
km = KMeans(n_clusters=num_clusters)
km.fit(x)
clusters = km.labels_.tolist()
print(clusters)
输出:
[2 2 0 0 1 1 0 0]
K-means 可以完美地处理数据。但是,簇号是在 0 ,1 和 2 之间随机生成的,没有顺序。
【问题讨论】:
-
您能否更具体地说明您要实现的目标?这里有什么问题?
-
你在说什么序列?
-
我想要像 0 0 1 1 2 2 1 1 这样的输出,而不是随机的,以便进一步处理
-
我不明白集群的名称有多重要,但既然你现在有一个可以修改的列表,那有什么问题?
-
请不要转发近乎重复的问题 Python K-means clustering on document。如果您花更多时间提出更好的问题,您可能会得到更好的答案。使用“编辑”选项来改进您的问题。
标签: python cluster-analysis data-mining k-means