
Ranked probability scores for ordinal classification models
Source:R/orderedprob-ranked_prob_score.R
ranked_prob_score.RdCompute the ranked probability score (RPS) for a classification model using ordered classes.
Usage
ranked_prob_score(data, ...)
# S3 method for class 'data.frame'
ranked_prob_score(data, truth, ..., na_rm = TRUE, case_weights = NULL)
ranked_prob_score_vec(truth, estimate, na_rm = TRUE, case_weights = NULL, ...)Arguments
- data
A
data.framecontaining the columns specified bytruthand....- ...
A set of unquoted column names or one or more
dplyrselector functions to choose which variables contain the class probabilities. Iftruthis binary, only 1 column should be selected, and it should correspond to the value ofevent_level. Otherwise, there should be as many columns as factor levels oftruthand the ordering of the columns should be the same as the factor levels oftruth.- truth
The column identifier for the true class results (that is an ordered
factor). This should be an unquoted column name although this argument is passed by expression and supports quasiquotation (you can unquote column names). For_vec()functions, a factor vector with classordered.- na_rm
A
logicalvalue indicating whetherNAvalues should be stripped before the computation proceeds.- case_weights
The optional column identifier for case weights. This should be an unquoted column name that evaluates to a numeric column in
data. For_vec()functions, a numeric vector,hardhat::importance_weights(), orhardhat::frequency_weights().- estimate
A matrix with as many columns as factor levels of
truth. It is assumed that these are in the same order as the levels oftruth.
Value
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 ranked_prob_score_vec(), a single numeric value (or NA).
Details
The ranked probability score is a Brier score for ordinal data that uses the
cumulative probability of an event (i.e. Pr[class <= i] for i = 1,
2, ..., C classes). These probabilities are compared to indicators for the
truth being less than or equal to class i.
Since the cumulative sum of a vector of probability predictions add up to one, there is an embedded redundancy in the data. For this reason, the raw mean is divided by the number of classes minus one.
Smaller values of the score are associated with better model performance.
Multiclass
Ranked probability scores can be computed in the same way for any number of classes. Because of this, no averaging types are supported.
References
Wilks, D. S. (2011). Statistical Methods in the Atmospheric Sciences. Academic press. (see Chapter 7)
Janitza, S., Tutz, G., & Boulesteix, A. L. (2016). Random forest for ordinal responses: prediction and variable selection. Computational Statistics and Data Analysis, 96, 57-73. (see Section 2)
Lechner, M., & Okasa, G. (2019). Random forest estimation of the ordered choice model. arXiv preprint arXiv:1907.02436. (see Section 5)
See also
Other class probability metrics:
average_precision(),
brier_class(),
classification_cost(),
gain_capture(),
mn_log_loss(),
pr_auc(),
roc_auc(),
roc_aunp(),
roc_aunu()
Examples
library(dplyr)
data(hpc_cv)
hpc_cv$obs <- as.ordered(hpc_cv$obs)
# You can use the col1:colN tidyselect syntax
hpc_cv |>
filter(Resample == "Fold01") |>
ranked_prob_score(obs, VF:L)
#> # A tibble: 1 × 3
#> .metric .estimator .estimate
#> <chr> <chr> <dbl>
#> 1 ranked_prob_score multiclass 0.0810
# Groups are respected
hpc_cv |>
group_by(Resample) |>
ranked_prob_score(obs, VF:L)
#> # A tibble: 10 × 4
#> Resample .metric .estimator .estimate
#> <chr> <chr> <chr> <dbl>
#> 1 Fold01 ranked_prob_score multiclass 0.0810
#> 2 Fold02 ranked_prob_score multiclass 0.0870
#> 3 Fold03 ranked_prob_score multiclass 0.0713
#> 4 Fold04 ranked_prob_score multiclass 0.0825
#> 5 Fold05 ranked_prob_score multiclass 0.0876
#> 6 Fold06 ranked_prob_score multiclass 0.0833
#> 7 Fold07 ranked_prob_score multiclass 0.0926
#> 8 Fold08 ranked_prob_score multiclass 0.0862
#> 9 Fold09 ranked_prob_score multiclass 0.0955
#> 10 Fold10 ranked_prob_score multiclass 0.0897