【发布时间】:2020-02-10 18:30:30
【问题描述】:
我已经阅读了很多博客,但对答案并不满意,假设我在几个文档示例上训练 tf-idf 模型:
" John like horror movie."
" Ryan watches dramatic movies"
------------so on ----------
我使用这个功能:
from sklearn.feature_extraction.text import TfidfTransformer
count_vect = CountVectorizer()
X_train_counts = count_vect.fit_transform(twenty_train.data)
X_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
print((X_train_counts.todense()))
# Gives count of words in each document
But it doesn't tell which word? How to get words as headers in X_train_counts
outputs. Similarly in X_train_tfidf ?
所以 X_train_tfidf 输出将是带有 tf-idf 分数的矩阵:
Horror watch movie drama
doc1 score1 -- -----------
doc2 ------------------------
这对吗?
fit 有什么作用,transformation 有什么作用?
在 sklearn 中提到:
fit(..) 方法使我们的估计器适合数据,其次是 transform(..) 方法将我们的计数矩阵转换为 tf-idf 表示。
estimator to the data 是什么意思?
现在假设新的测试文件来了:
" Ron likes thriller movies"
如何将此文档转换为 tf-idf?我们不能将其转换为 tf-idf 对吧?
如何处理火车文档中没有的单词thriller。
【问题讨论】:
标签: python-3.x scikit-learn tf-idf