dx_balanced_accuracy | R Documentation |
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.
dx_balanced_accuracy(cm, detail = "full", boot = FALSE, bootreps = 1000)
cm |
A dx_cm object created by |
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. |
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}
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.
dx_cm()
to understand how to create and interact with a 'dx_cm' object.
dx_sensitivity()
, dx_specificity()
for the components of balanced accuracy.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.