ranked_prob_score: Ranked probability scores for ordinal classification models

View source: R/orderedprob-ranked_prob_score.R

ranked_prob_scoreR Documentation

Ranked probability scores for ordinal classification models

Description

Compute 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.frame containing the columns specified by truth and ....

...

A set of unquoted column names or one or more dplyr selector functions to choose which variables contain the class probabilities. If truth is binary, only 1 column should be selected, and it should correspond to the value of event_level. Otherwise, there should be as many columns as factor levels of truth and the ordering of the columns should be the same as the factor levels of truth.

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 class ordered.

na_rm

A logical value indicating whether NA values 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(), or hardhat::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 of truth.

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.

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).

Multiclass

Ranked probability scores can be computed in the same way for any number of classes. Because of this, no averaging types are supported.

Author(s)

Max Kuhn

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)

# Groups are respected
hpc_cv %>%
  group_by(Resample) %>%
  ranked_prob_score(obs, VF:L)


tidymodels/yardstick documentation built on April 13, 2025, 3:56 p.m.