Apply a feature-weighting scheme to a quanteda quanteda::dfm. This wraps
quanteda::dfm_tfidf() and quanteda::dfm_weight() behind a single verb so
weighting stays inside the NLPstudio API.
Usage
weight_dfm(
x,
scheme = c("tfidf", "count", "prop", "propmax", "logcount", "boolean", "augmented",
"logave"),
...
)Arguments
- x
A quanteda::dfm object.
- scheme
Character. Weighting scheme.
"tfidf"(default) appliesquanteda::dfm_tfidf(); every other scheme is passed toquanteda::dfm_weight():"count","prop","propmax","logcount","boolean","augmented", or"logave".- ...
Additional arguments passed to the underlying quanteda function (e.g.
scheme_tforbasefor"tfidf").
Value
A weighted quanteda::dfm.
Examples
corp <- quanteda::corpus(c(
doc1 = "money money risk",
doc2 = "risk growth growth growth"
))
dfmat <- quanteda::dfm(tokenize_corpus(corp))
#>
#> ── Tokenizing corpus ──
#>
#> ℹ quanteda::tokens() has been called with default parameters
#> ✔ Corpus successfully tokenized
weight_dfm(dfmat, scheme = "tfidf")
#>
#> ── Weighting dfm ──
#>
#> ℹ scheme = tfidf
#> ✔ Weighting complete
#> Document-feature matrix of: 2 documents, 3 features (33.33% sparse) and 0 docvars.
#> features
#> docs money risk growth
#> doc1 0.60206 0 0
#> doc2 0 0 0.90309
