Skip to contents

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) applies quanteda::dfm_tfidf(); every other scheme is passed to quanteda::dfm_weight(): "count", "prop", "propmax", "logcount", "boolean", "augmented", or "logave".

...

Additional arguments passed to the underlying quanteda function (e.g. scheme_tf or base for "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