简短的回答是这是文档中的一个“错误”(对于 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 错误 导致它错误地计算:
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 中修复。