k-means 聚类示范

from sklearn.cluster import KMeans
import numpy as np
 
num_clusters = 2
km_cluster = KMeans(n_clusters=num_clusters, max_iter=300, n_init=40, \
                    init='k-means++',n_jobs=-1)
tfidf_matrix=np.random.rand(200,100)

#返回各自文本的所被分配到的类索引

result = km_cluster.fit_predict(tfidf_matrix)
print(km_cluster.cluster_centers_[0].shape)
 
print("Predicting result: ", result)

 

你可能感兴趣的:(ML,PY)