View source: R/prob-brier_class.R
| brier_class | R Documentation |
Compute the Brier score for a classification model.
brier_class(data, ...)
## S3 method for class 'data.frame'
brier_class(
data,
truth,
...,
na_rm = TRUE,
event_level = yardstick_event_level(),
case_weights = NULL
)
brier_class_vec(
truth,
estimate,
na_rm = TRUE,
event_level = yardstick_event_level(),
case_weights = NULL,
...
)
data |
A |
... |
A set of unquoted column names or one or more
|
truth |
The column identifier for the true class results
(that is a |
na_rm |
A |
event_level |
A single string. Either |
case_weights |
The optional column identifier for case weights.
This should be an unquoted column name that evaluates to a numeric column
in |
estimate |
If |
Brier score is a metric that should be minimized. The output ranges from 0 to 1, with 0 indicating perfect predictions.
The Brier score is analogous to the mean squared error in regression models. The difference between a binary indicator for a class and its corresponding class probability are squared and averaged.
The formula used here is:
\text{Brier} = \frac{1}{2N} \sum_{i=1}^{N} \sum_{j=1}^{K} (y_{ij} - p_{ij})^2
where N is the number of observations, K is the number of classes,
y_{ij} is 1 if observation i belongs to class j and 0
otherwise, and p_{ij} is the predicted probability of observation
i for class j.
This function uses the convention in Kruppa et al (2014) and divides the result by two.
Smaller values of the score are associated with better model performance.
A tibble with columns .metric, .estimator,
and .estimate and 1 row of values.
For grouped data frames, the number of rows returned will be the same as the number of groups.
For brier_class_vec(), a single numeric value (or NA).
Brier scores can be computed in the same way for any number of classes. Because of this, no averaging types are supported.
There is no common convention on which factor level should
automatically be considered the "event" or "positive" result
when computing binary classification metrics. In yardstick, the default
is to use the first level. To alter this, change the argument
event_level to "second" to consider the last level of the factor the
level of interest. For multiclass extensions involving one-vs-all
comparisons (such as macro averaging), this option is ignored and
the "one" level is always the relevant result.
Max Kuhn
Kruppa, J., Liu, Y., Diener, H.-C., Holste, T., Weimar, C., Koonig, I. R., and Ziegler, A. (2014) Probability estimation with machine learning methods for dichotomous and multicategory outcome: Applications. Biometrical Journal, 56 (4): 564-583.
All probability metrics
Other class probability metrics:
average_precision(),
classification_cost(),
gain_capture(),
mn_log_loss(),
pr_auc(),
ranked_prob_score(),
roc_auc(),
roc_aunp(),
roc_aunu()
# Two class
data("two_class_example")
brier_class(two_class_example, truth, Class1)
# Multiclass
library(dplyr)
data(hpc_cv)
# You can use the col1:colN tidyselect syntax
hpc_cv |>
filter(Resample == "Fold01") |>
brier_class(obs, VF:L)
# Groups are respected
hpc_cv |>
group_by(Resample) |>
brier_class(obs, VF:L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.