catAccuracy: Accuracy by categories

View source: R/catAccuracy.R

catAccuracyR Documentation

Accuracy by categories

Description

Checks accuracy of classification by category. Provides details by category including: true positive rate, positive predicted value, true frequency in training data, and the top five classes observations from a given category are mistakenly classified into.

Usage

catAccuracy(true, predicted, latexfile = FALSE,
  filename = "category_accuracy.tex")

Arguments

true

The numeric vector of true codings

predicted

One numeric vector of predicted codings from classifyNB

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 category_accuracy.tex

Value

A dataframe with one row for each class. Columns correspond to within-class measures of: true positive rate, positive predicted value, true frequency in training data, and the top five classes observations from the given category are mistakenly classified into.

Note

Latex table outputs depend on the Latex packages: longtable and xcolor. Include the lines: \usepackage\[table\]{xcolor} \usepackage{longtable} in 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)

  ## Convert matrix of frequencies to matrix of indicators
  train_matrix@x[train_matrix@x > 1] <- 1

  est <- trainNB(training_agendas$coding, train_matrix)
  out <- classifyNB(est, train_matrix, training_agendas)
  acc <- catAccuracy(true = out$coding, predicted = out$ratio_match)


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