Skip to contents

Calculates the F-beta score from a confusion matrix object with an option to include bootstrapped confidence intervals. The F-beta score is a generalization of the F1 score, allowing different importance to precision and recall via the beta parameter.

Usage

dx_fbeta(cm, beta = 1, detail = "full", boot = FALSE, bootreps = 2000)

Arguments

cm

A dx_cm object created by dx_cm().

beta

A single number greater than 0. Recall is weighted beta times as much as precision: values above 1 favor recall and values below 1 favor precision.

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 a percentile bootstrap of the confusion matrix cell counts. With the default, FALSE, no confidence interval is reported. Call set.seed() first for reproducible intervals.

bootreps

The number of bootstrap replications for calculating confidence intervals.

Value

Depending on the detail parameter, returns a single numeric value of F-beta or a data frame with the F-beta and, when boot = TRUE, its confidence interval.

Details

$$F_\beta = (1 + \beta^2) \frac{Precision \times Recall}{\beta^2 \times Precision + Recall}$$

The score is 0 when precision and recall are both 0 or undefined.

See also

dx_f1(), dx_f2() for specific F-beta scores.

Examples

cm <- dx_cm(dx_heart_failure$predicted, dx_heart_failure$truth,
  threshold =
    0.5, poslabel = 1
)
simple_f <- dx_fbeta(cm, beta = .5, detail = "simple")
detailed_f <- dx_fbeta(cm, beta = .5)
print(simple_f)
#> [1] 0.8056872
print(detailed_f)
#> # A tibble: 1 × 8
#>   measure    summary estimate conf_low conf_high fraction conf_type notes       
#>   <chr>      <chr>      <dbl>    <dbl>     <dbl> <chr>    <chr>     <chr>       
#> 1 F0.5 Score 0.81       0.806       NA        NA ""       NA        Specify `bo…