【发布时间】:2017-08-22 19:21:46
【问题描述】:
我正在尝试在某个文本语料库上拟合 tfidf 矢量化器,然后使用相同的矢量化器来查找新文本的 tfidf 值的总和。但是,总和值与预期不符。下面是例子:
text = ["I am new to python and R , how can anyone help me","why is no one able to crack the python code without help"]
tf= TfidfVectorizer(stop_words='english',ngram_range =(1,1))
tf.fit_transform(text)
zip(tf.get_feature_names(),tf.idf_)
[(u'able', 1.4054651081081644),
(u'code', 1.4054651081081644),
(u'crack', 1.4054651081081644),
(u'help', 1.0),
(u'new', 1.4054651081081644),
(u'python', 1.0)]
现在,当我尝试使用相同的 tf 新文本时:
new_text = "i am not able to code"
np.sum(tf.transform([new_text]))
1.4142135623730951
我预计输出在 2.80 左右。任何关于此处可能出现问题的建议都会非常有帮助。
【问题讨论】:
标签: python python-2.7 scikit-learn tf-idf