R/score_binary.R

Defines functions score_binary

Documented in score_binary

#' @title Evaluate forecasts in a Binary Format
#'
#' @inheritParams score
#' @param forecast_unit A character vector with the column names that define
#' the unit of a single forecast, i.e. a forecast was made for a combination
#' of the values in `forecast_unit`.
#'
#' @return A data.table with appropriate scores. For more information see
#' [score()].
#'
#' @importFrom data.table ':='
#'
#' @author Nikos Bosse \email{nikosbosse@@gmail.com}
#' @keywords internal

score_binary <- function(data,
                         forecast_unit,
                         metrics) {
  if ("brier_score" %in% metrics) {
    data[, "brier_score" := brier_score(true_value, prediction),
      by = forecast_unit
    ]
  }

  if ("log_score" %in% metrics) {
    data[, "log_score" := logs_binary(true_value, prediction),
      by = forecast_unit
    ]
  }

  return(data[])
}

Try the scoringutils package in your browser

Any scripts or data that you put into this service are public.

scoringutils documentation built on Feb. 16, 2023, 7:30 p.m.