赞
踩
接上一篇<sklearn文本特征预处理1: WordPunctTokenizer, CountVectorizer, TF-IDF>
# 余弦相似度
from sklearn.metrics.pairwise import cosine_similarity
similarity_matrix = cosine_similarity(tv_matrix)
similarity_df = pd.DataFrame(similarity_matrix)
similarity_df
from sklearn.cluster import KMeans
km = KMeans(n_clusters = 2)
km.fit_transform(similarity_df)
cluster_labels = km.labels_
cluster_labels = pd.DataFrame(cluster_labels, columns=['ClusterLabel'])
pd.concat
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。