catAccuracy | R Documentation |
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.
catAccuracy(true, predicted, latexfile = FALSE,
filename = "category_accuracy.tex")
true |
The numeric vector of true codings |
predicted |
One numeric vector of predicted codings from |
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 |
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.
Latex table outputs depend on the Latex packages: longtable and xcolor. Include the lines:
\usepackage\[table\]{xcolor}
\usepackage{longtable}
in Latex header
Matt W. Loftis
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.