0

我的问题很简单,R 中的 Quanteda 包具有计算文档频率矩阵(dfm)的词频(tf)的功能。当你用 ?tf 查看 tf 函数的描述时,它说它有四个参数。我的问题是关于“方案”的论点。我不明白如何使用 maxCount 选项,即使用每个文档的最大特征数作为 tf. 当您查看“用法”时,方案参数的唯一选项是“count”、“prop”、“propmax”、“boolean”、“log”、“augmented”和“logave”,那么,我该如何使用maxCount 选项?

4

1 回答 1

1

简短的回答是,这是文档中的一个“错误”(对于 quanteda 0.9.8.0-0.9.8.2),因为该选项已从函数中删除,但未从文档中删除。新语法是propMax参数,例如:

txt <- c(doc1 = "This is a simple, simple, simple document.",
         doc2 = "This document is a second document.")
(myDfm <- dfm(txt, verbose = FALSE))
## Document-feature matrix of: 2 documents, 6 features.
## 2 x 6 sparse Matrix of class "dfmSparse"
##       features
## docs   this is a simple document second
##   doc1    1  1 1      3        1      0
##   doc2    1  1 1      0        2      1

应用权重:

tf(myDfm, scheme = "prop")
## Document-feature matrix of: 2 documents, 6 features.
## 2 x 6 sparse Matrix of class "dfmSparse"
##       features
## docs        this        is         a    simple  document    second
##   doc1 0.1428571 0.1428571 0.1428571 0.4285714 0.1428571 0        
##   doc2 0.1666667 0.1666667 0.1666667 0         0.3333333 0.1666667

propmax应该计算每个计数相对于文档中最频繁计数的比例。例如,对于 doc1,最大特征数为 3,因此该文档中的每个术语都将除以 3。但是在 quanteda <=0.9.8.2 中,有一个错误导致它错误地计算:

tf(myDfm, scheme = "propmax")
## Document-feature matrix of: 2 documents, 6 features.
## 2 x 6 sparse Matrix of class "dfmSparse"
##       features
## docs        this        is         a simple  document    second
##   doc1 1.0000000 1.0000000 1.0000000      3 1.0000000 0        
##   doc2 0.3333333 0.3333333 0.3333333      0 0.6666667 0.3333333

在 quanteda v0.9.8.3 中,这是固定的:

tf(myDfm, scheme = "propmax")
## Document-feature matrix of: 2 documents, 6 features.
## 2 x 6 sparse Matrix of class "dfmSparse"
##       features
## docs        this        is         a simple  document second
##   doc1 0.3333333 0.3333333 0.3333333      1 0.3333333    0  
##   doc2 0.5000000 0.5000000 0.5000000      0 1.0000000    0.5

注意:在 0.9.8.3 中修复。

于 2016-10-14T18:57:57.207 回答