当前位置: 代码迷 >> 综合 >> sklearn文本特征预处理2:Similarity, 聚类, LDA, word2vec
  详细解决方案

sklearn文本特征预处理2:Similarity, 聚类, LDA, word2vec

热度:84   发布时间:2023-12-20 21:58:23.0

接上一篇<sklearn文本特征预处理1: WordPunctTokenizer, CountVectorizer, TF-IDF>

五. Similarity特征

# 余弦相似度
from sklearn.metrics.pairwise import cosine_similaritysimilarity_matrix = cosine_similarity(tv_matrix)
similarity_df = pd.DataFrame(similarity_matrix)
similarity_df

在这里插入图片描述

六. 聚类特征

from sklearn.cluster import KMeanskm = KMeans(n_clusters = 2)
km.fit_transform(similarity_df)
cluster_labels = km.labels_
cluster_labels = pd.DataFrame(cluster_labels, columns=['ClusterLabel'])
pd.concat
  相关解决方案