반응형
documents = ["Human machine interface for lab abc computer applications",
"A survey of user opinion of computer system response time",
"The EPS user interface management system",
"System and human system engineering testing of EPS",
"Relation of user perceived response time to error measurement",
"The generation of random binary unordered trees",
"The intersection graph of paths in trees",
"Graph minors IV Widths of trees and well quasi ordering",
"Graph minors A survey"]
해결 방법
다음은 더 간단한 예입니다.
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cluster import KMeans
from sklearn.metrics import adjusted_rand_score
documents = ["Human machine interface for lab abc computer applications",
"A survey of user opinion of computer system response time",
"The EPS user interface management system",
"System and human system engineering testing of EPS",
"Relation of user perceived response time to error measurement",
"The generation of random binary unordered trees",
"The intersection graph of paths in trees",
"Graph minors IV Widths of trees and well quasi ordering",
"Graph minors A survey"]
vectorizer = TfidfVectorizer(stop_words='english')
X = vectorizer.fit_transform(documents)
true_k = 2
model = KMeans(n_clusters=true_k, init='k-means++', max_iter=100, n_init=1)
model.fit(X)
print("Top terms per cluster:")
order_centroids = model.cluster_centers_.argsort()[:, ::-1]
terms = vectorizer.get_feature_names()
for i in range(true_k):
print "Cluster %d:" % i,
for ind in order_centroids[i, :10]:
print ' %s' % terms[ind],
print
참조 페이지 https://stackoverflow.com/questions/27889873
반응형
'파이썬' 카테고리의 다른 글
파이썬 Python에서 라인 히스토그램 차트를 생성하는 깨끗한 방법이 있습니까? (0) | 2020.12.02 |
---|---|
파이썬 Date difference in minutes in Python (0) | 2020.12.02 |
파이썬 Reading tab-delimited file with Pandas - works on Windows, but not on Mac (0) | 2020.12.02 |
파이썬 Pandas DataFrame의 선행 값으로 NaN을 대체하는 방법은 무엇입니까? (0) | 2020.12.01 |
파이썬 하나의 파일에서 여러 JSON 객체를 추출하는 방법은 무엇입니까? (0) | 2020.12.01 |
댓글