как выбрать кластер с максимальной частотой в k означает - PullRequest
0 голосов
/ 09 января 2020

Я создал кластер средств из Gensim word2ve c, где значение k равно 3. Теперь я хочу получить кластер и значения, где частота наиболее.

import gensim
from gensim.models import Word2Vec
import nltk
from nltk.tokenize import sent_tokenize
from sklearn.cluster import KMeans
import numpy as np
text = "Thank you for keeping me updated on this issue. I'm happy to hear that the issue got resolved after all and you can now use the app in its full functionality again. Also many thanks for <pre> your suggestions. We hope to improve this feature in the future. In case you experience any <pre> further problems with the app, please don't hesitate to contact me again."
sentences = sent_tokenize(text)
word_text = [[text for text in sentences.split()] for sentences in sentences]
model = Word2Vec(word_text, min_count=1)
x = model[model.wv.vocab]
n_clusters = 3
kmeans = KMeans(n_clusters=n_clusters)
kmeans = kmeans.fit(x)

1 Ответ

1 голос
/ 09 января 2020

Вы можете найти метки каждой точки данных:

labels = kmeans.labels_

Теперь вы можете найти количество выборок в каждом кластере, используя:

np.unique(labels, return_counts=True)

и вы можете найти центры кластеров, используя kmeans.cluster_centers_

...