2024-06-22 10:35:12 发布
网友
我正在跟踪example in Scikit learn docs,其中CountVectorizer用于某些数据集。
CountVectorizer
问题:count_vect.vocabulary_.viewitems()列出所有术语及其频率。你如何根据发生的次数来分类?
count_vect.vocabulary_.viewitems()
sorted( count_vect.vocabulary_.viewitems() )似乎不起作用。
sorted( count_vect.vocabulary_.viewitems() )
vocabulary_.viewitems()实际上并不列出术语及其频率,而是从术语到索引的映射。频率(每个文档)由fit_转换方法返回,该方法返回一个稀疏(coo)矩阵,其中行是文档,列是单词(列索引通过词汇表映射到单词)。例如,您可以通过
vocabulary_.viewitems()
matrix = count_vect.fit_transform(doc_list) freqs = zip(count_vect.get_feature_names(), matrix.sum(axis=0)) # sort from largest to smallest print sorted(freqs, key=lambda x: -x[1])
vocabulary_.viewitems()
实际上并不列出术语及其频率,而是从术语到索引的映射。频率(每个文档)由fit_转换方法返回,该方法返回一个稀疏(coo)矩阵,其中行是文档,列是单词(列索引通过词汇表映射到单词)。例如,您可以通过相关问题 更多 >
编程相关推荐