dx_balanced_accuracy: Calculate Balanced Accuracy

View source: R/dx_metrics.R

dx_balanced_accuracyR Documentation

Calculate Balanced Accuracy

Description

Calculates Balanced Accuracy, which is the average of sensitivity (recall) and specificity. This metric is particularly useful for imbalanced datasets as it accounts for both the positive and negative classes equally and doesn't inherently favor the majority class.

Usage

dx_balanced_accuracy(cm, detail = "full", boot = FALSE, bootreps = 1000)

Arguments

cm

A dx_cm object created by dx_cm().

detail

Character specifying the level of detail in the output: "simple" for raw estimate, "full" for detailed estimate including 95% confidence intervals.

boot

Logical specifying if confidence intervals should be generated via bootstrapping. Note, this can be slow.

bootreps

The number of bootstrap replications for calculating confidence intervals.

Details

Balanced Accuracy mitigates the issue of the regular accuracy metric favoring models that predict the majority class in an imbalanced dataset. By taking the average of sensitivity and specificity, it gives a better measure of the overall performance especially when classes are imbalanced or when costs of different errors vary greatly.

The formula for Balanced Accuracy is:

Balanced Accuracy = \frac{Sensitivity + Specificity}{2}

Value

Depending on the detail parameter, returns a numeric value representing the calculated metric or a data frame/tibble with detailed diagnostics including confidence intervals and possibly other metrics relevant to understanding the metric.

See Also

dx_cm() to understand how to create and interact with a 'dx_cm' object.

dx_sensitivity(), dx_specificity() for the components of balanced accuracy.

Examples

cm <- dx_cm(dx_heart_failure$predicted, dx_heart_failure$truth, threshold = 0.5, poslabel = 1)
simple_balanced_accuracy <- dx_balanced_accuracy(cm, detail = "simple")
detailed_balanced_accuracy <- dx_balanced_accuracy(cm)
print(simple_balanced_accuracy)
print(detailed_balanced_accuracy)

overdodactyl/diagnosticSummary documentation built on Jan. 28, 2024, 10:07 a.m.