【发布时间】:2017-11-14 22:11:52
【问题描述】:
我有一个来自 ISI 论文的 tf-idf 示例。我试图通过这个例子来验证我的代码。但是我的代码得到了不同的结果。我不知道是什么原因!
论文中的术语-文档矩阵:
acceptance [ 0 1 0 1 1 0
information 0 1 0 1 0 0
media 1 0 1 0 0 2
model 0 0 1 1 0 0
selection 1 0 1 0 0 0
technology 0 1 0 1 1 0]
论文中的Tf-idf矩阵:
acceptance [ 0 0.4 0 0.3 0.7 0
information 0 0.7 0 0.5 0 0
media 0.3 0 0.2 0 0 1
model 0 0 0.6 0.5 0 0
selection 0.9 0 0.6 0 0 0
technology 0 0.4 0 0.3 0.7 0]
我的 tf-idf 矩阵:
acceptance [ 0 0.4 0 0.3 0.7 0
information 0 0.7 0 0.5 0 0
media 0.5 0 0.4 0 0 1
model 0 0 0.6 0.5 0 0
selection 0.8 0 0.6 0 0 0
technology 0 0.4 0 0.3 0.7 0]
我的代码:
tfidf = models.TfidfModel(corpus)
corpus_tfidf=tfidf[corpus]
我尝试了另一个类似这样的代码:
transformer = TfidfTransformer()
tfidf=transformer.fit_transform(counts).toarray() ##counts is term-document matrix
但我没有得到合适的答案
【问题讨论】:
-
你的语料库是什么?
-
@Mahmood Kohansal -- 字典:'{u'media': 0, u'technolog': 3, u'accept': 4, u'inform': 2, u'model': 5、u'select': 1}' 和语料库:' [[(0, 1), (1, 1)], [(2, 1), (3, 1), (4, 1)], [ (0, 1), (1, 1), (5, 1)], [(2, 1), (3, 1), (4, 1), (5, 1)], [(3, 1 ), (4, 1)], [(0, 2)]] '