Kmeans fit_predict 与 word2vec
Kmeans fit_predict with word2vec
我正尝试按照 here 所述使用 kmeans 对我的词向量进行聚类。
我使用的代码片段
# 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 )
我收到以下错误
类型错误:'float' 对象不能解释为整数
有人可以帮忙吗
发现错误。簇数必须是整数,所以我做了以下
num_clusters = 整数(word_vectors.shape[0] / 5)
我正尝试按照 here 所述使用 kmeans 对我的词向量进行聚类。 我使用的代码片段
# 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 )
我收到以下错误 类型错误:'float' 对象不能解释为整数
有人可以帮忙吗
发现错误。簇数必须是整数,所以我做了以下
num_clusters = 整数(word_vectors.shape[0] / 5)