【发布时间】:2017-08-25 11:03:58
【问题描述】:
虽然有六个不同的词。结果中只打印了 5 个单词。如何根据所有单词(6列向量)得到结果?
from sklearn.feature_extraction.text import TfidfVectorizer
sent=["This is a sample", "This is another example"]
tf = TfidfVectorizer(analyzer='word', ngram_range=(1,1), min_df = 0)
tfidf_matrix = tf.fit_transform(sent)
print tfidf_matrix.toarray()
[[ 0. 0. 0.50154891 0.70490949 0.50154891] [ 0.57615236 0.57615236 0.40993715 0.0.40993715]]
还有如何打印列详细信息(特征(单词))和行(文档)?
【问题讨论】:
标签: python scikit-learn nlp tf-idf