topWords: Find top words by category

View source: R/topWords.R

topWordsR Documentation

Find top words by category

Description

Identifies training words (features) most associated with each class in the training data.

Usage

topWords(est, latexfile = FALSE, filename = "topwords.tex")

Arguments

est

The output object from trainNB

latexfile

Logical indicating whether the user wants a latex table of results output into the current working directory.

filename

String name for the output file. Defaults to topwords.tex

Value

A dataframe with one row for each class. Columns correspond to class name and the top five words associated with the respective class.

Note

Latex table outputs depend on the Latex packages: longtable and xcolor. Include the lines: \usepackage\[table\]{xcolor} \usepackage{longtable} in the Latex header

Author(s)

Matt W. Loftis

Examples

## Load data and create document-feature matrices
train_corpus <- quanteda::corpus(x = training_agendas$text)
train_matrix <- quanteda::dfm(train_corpus,
                    language = "danish",
                    stem = TRUE,
                    removeNumbers = FALSE)

est <- trainNB(training_agendas$coding, train_matrix)
words <- topWords(est)


mattwloftis/agendacodeR documentation built on June 5, 2023, 7 p.m.