calc_accuracy_per_class.Rd
Calculates the accuracy of a predictive model for each class.
calc_accuracy_per_class( x, target_col_name, target_pred_col_name, column_names = NULL )
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 |
A data frame/tibble with as many rows as the number of unique labels.
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:
When column_names
is NULL
, then the returned data frame names
are c(target_col_name, "accuracy")
.
When column_names
is a vector of strings, the returned data
frame names are as in the vector.
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" )#> # A tibble: 6 x 2 #> carb accuracy #> <dbl> <dbl> #> 1 1 0.143 #> 2 2 0.2 #> 3 3 0 #> 4 4 0.4 #> 5 6 0 #> 6 8 0# 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") )#> # A tibble: 6 x 2 #> class accuracy_per_class #> <dbl> <dbl> #> 1 1 0 #> 2 2 0.1 #> 3 3 0 #> 4 4 0.3 #> 5 6 0 #> 6 8 0