Skip to contents

Calculates the F1 score from a confusion matrix object with an option to include bootstrapped confidence intervals. The F1 score is the harmonic mean of precision and recall.

Usage

dx_f1(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.

Value

Depending on the detail parameter, returns a single numeric value of F1 or a data frame with the F1 and its confidence intervals.

See also

dx_fbeta(), dx_f2() for other F-beta scores.

Examples

cm <- dx_cm(dx_heart_failure$predicted, dx_heart_failure$truth,
  threshold =
    0.5, poslabel = 1
)
simple_f <- dx_f1(cm, detail = "simple")
detailed_f <- dx_f1(cm)
print(simple_f)
#> [1] 0.7597765
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 F1 Score 0.76       0.760       NA        NA ""       NA        Specify `boot…