У меня есть этот код kmeans.
kmeans = KMeans(n_clusters = 10, n_init = 20, n_jobs = 1)
kmeans.fit(X3)
# Finally, we look at 10 the clusters generated by k-means.
common_words = kmeans.cluster_centers_.argsort()[:,-1:-26:-1]
for num, centroid in enumerate(common_words):
print(str(num) + ' : ' + ', '.join(words[word] for word in centroid))
Это дает мне этот массив.
common_words
array([[552, 164, 978, 222, 502, 326, 731, 960, 225, 253, 60, 486, 964,
612, 56, 176, 436, 584, 797, 270, 61, 694, 875, 599, 163],
[218, 380, 645, 400, 111, 207, 787, 938, 964, 706, 752, 340, 127,
158, 241, 510, 722, 422, 568, 692, 777, 774, 269, 163, 427],
[474, 323, 597, 16, 829, 491, 818, 249, 556, 638, 779, 656, 228,
977, 125, 493, 177, 585, 660, 404, 160, 573, 1, 167, 618],
[591, 515, 645, 994, 218, 612, 656, 158, 440, 444, 252, 797, 43,
442, 541, 167, 400, 37, 559, 762, 796, 969, 326, 573, 427],
[656, 476, 676, 552, 781, 453, 607, 574, 253, 146, 164, 48, 293,
787, 807, 56, 54, 584, 225, 289, 336, 871, 960, 700, 774],
[645, 774, 400, 938, 964, 690, 408, 163, 694, 615, 581, 422, 599,
768, 508, 731, 734, 953, 406, 335, 942, 865, 7, 427, 933]],
dtype=int64)
Я пытаюсь выяснить, как я могу построить это.
Я попробовал это.
import matplotlib.pyplot as plt
plt.scatter(common_words[:, 0], common_words[:, 1], s=50, cmap='viridis')
centers = kmeans.cluster_centers_
plt.scatter(centers[:, 0], centers[:, 1], c='black', s=200, alpha=0.5)
Я получаю это (что явно не правильно).
отсюда поступает набор данных.
https://www.kaggle.com/therohk/million-headlines