我有一个来自ISI论文的tf-idf示例。我试图通过这个例子验证我的代码。但是我从我的代码中得到了不同的结果。我不知道原因是什么!从纸使用gensim的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]
我的代码:
从纸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矩阵
tfidf = models.TfidfModel(corpus)
corpus_tfidf=tfidf[corpus]
我尝试另一个像这样的代码:
transformer = TfidfTransformer()
tfidf=transformer.fit_transform(counts).toarray() ##counts is term-document matrix
但是,正如你提到的是,有许多方法来计算TF我没有得到合适的答案
什么是你的语料库? –
@Mahmood Kohansal - 词典:'{u'media':0,u'technolog':3,u'accept':4,u'inform':2,u'model':5,u'select': (1,1)'和语料库:[[(0,1),(1,1)],[(2,1),(3,1),(4,1)],[(0,1),( (1,1,1),(5,1)],[(2,1),(3,1),(4,1),(5,1)],[(3,1),(4,1) ],[(0,2)]]' – mahshid