【发布时间】:2019-09-01 17:17:42
【问题描述】:
如何使用 Tf-idf 从语料库中查找单个单词的频率。下面是我的示例代码,现在我想打印一个单词的频率。我怎样才能做到这一点?
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
corpus = ['This is the first document.',
'This is the second second document.',
'And the third one.',
'Is this the first document?',]
X = vectorizer.fit_transform(corpus)
X
print(vectorizer.get_feature_names())
X.toarray()
vectorizer.vocabulary_.get('document')
print(vectorizer.get_feature_names())
X.toarray()
vectorizer.vocabulary_.get('document')
【问题讨论】:
标签: python nlp tf-idf n-gram countvectorizer