Kmeans fit_predict 与 word2vec

LGG*_*LGG 3 k-means python-3.x word2vec

我想用集群作为K均值描述我的单词矢量这里。我正在使用的代码片段

# Set "k" (num_clusters) to be 1/5th of the vocabulary size, or an
# average of 5 words per cluster
word_vectors = model.syn0
num_clusters = word_vectors.shape[0] / 5

# Initalize a k-means object and use it to extract centroids
kmeans_clustering = KMeans( n_clusters = num_clusters )
idx = kmeans_clustering.fit_predict( word_vectors )
Run Code Online (Sandbox Code Playgroud)

我收到以下错误 TypeError: 'float' object cannot be interpret as an integer

有人可以帮忙吗

LGG*_*LGG 5

发现错误。簇数必须是整数所以我做了以下

num_clusters = int(word_vectors.shape[0] / 5)