【发布时间】:2018-06-02 01:56:51
【问题描述】:
此代码用于对每个集群进行索引和排序,以确定哪些是最接近集群质心的前 n 个(我选择 n=6)单词。 无论如何,我发现了这种错误: 'float' 对象没有属性 'encode'
谁能帮助我? 代码如下:
from __future__ import print_function
print("Top terms per cluster:")
print()
#sort cluster centers by proximity to centroid
order_centroids = km.cluster_centers_.argsort()[:, ::-1]
for i in range(num_clusters):
print("Cluster %d words:" % i, end='')
for ind in order_centroids[i, :6]: #replace 6 with n words per cluster
print(' %s' % vocab_frame.ix[terms[ind].split(' ')].values.tolist()[0][0].encode('utf-8', 'ignore'), end=',')
print() #add whitespace
print() #add whitespace
print("Cluster %d titles:" % i, end='')
for title in frame.ix[i]['title'].values.tolist():
print(' %s,' % title, end='')
print() #add whitespace
print() #add whitespace
print()
print()
提前谢谢你
【问题讨论】:
-
Anyway, i found this kind of error在哪一行?
标签: python python-3.x cluster-analysis topic-modeling