2017-12-19 10 views
-2

이 코드는 각 클러스터에서 인덱싱 및 정렬하여 클러스터 중도에 가장 가까운 상위 n 개 (n = 6을 선택) 단어를 식별합니다. 어쨌든 이런 종류의 오류가 발견되었습니다. 'float'객체에 'encode'속성이 없습니다.'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() 

은 문자열에 적용 할 수있는 사전

+0

'어쨌든이 종류의 오류가 발견되었습니다. ' –

답변

0

방법 encode에 감사 수레하지.

플로트를 문자열로 변환 할 수는 있지만 분명히 의미가 없습니다.

당신이 이해할 수없는 인터넷의 붙여 넣기 코드 &이 나타납니다. 어쩌면 먼저 코드를 이해하고 실행해야합니다. 코드를 이해하고 나면 오류의 출처와 오류를 올바르게 수정하는 방법이 명확해야합니다.