我想用集群作为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 )
我收到以下错误TypeError:“ float”对象无法解释为整数
有人可以帮忙吗
发现错误。簇数必须是整数,所以我做了以下工作
num_clusters = int(word_vectors.shape [0] / 5)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句