calc_accuracy_per_class: Calculate classifier accuracy for each class and group

Description Usage Arguments Details Value Examples

View source: R/calc_accuracy_per_class.R

Description

Calculates the accuracy of a predictive model for each class.

Usage

1
2
3
4
5
6
calc_accuracy_per_class(
  x,
  target_col_name,
  target_pred_col_name,
  column_names = NULL
)

Arguments

x

A data frame with two columns: the column with the actual classes; and the column with the predicted classes. Any other columns will be ignored.

target_col_name

A string with the column name of the target variable.

target_pred_col_name

A string with the column name of the predictions for the target variable.

column_names

A vector of strings or NULL, used to specify the names of the returned data frame/tibble. See Details.

Details

This function was originally designed for use with package {pxtextminingdashboard}, in which case column_names is set to c("class", "accuracy"). It can, however, be used outside the context of{pxtextminingdashboard}, by controlling the column_names argument:

Value

A data frame/tibble with as many rows as the number of unique labels.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(experienceAnalysis)
mtcars %>%
  dplyr::mutate(carb_pred = sample(carb, size = nrow(.))) %>%  # Mock predictions column
  calc_accuracy_per_class(
    target_col_name = "carb",
    target_pred_col_name = "carb_pred"
  )

# Custom column names
mtcars %>%
  dplyr::mutate(carb_pred = sample(carb, size = nrow(.))) %>%  # Mock predictions column
  calc_accuracy_per_class(
    target_col_name = "carb",
    target_pred_col_name = "carb_pred",
    column_names = c("class", "accuracy_per_class")
  )

CDU-data-science-team/experienceAnalysis documentation built on Dec. 17, 2021, 12:53 p.m.