From 3619b0db4a451d16eb77981106049fc3f306f5c8 Mon Sep 17 00:00:00 2001 From: mb706 Date: Thu, 17 Apr 2025 17:14:35 +0200 Subject: [PATCH 1/7] small doc change --- R/classif_acc.R | 6 +++--- man/acc.Rd | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/classif_acc.R b/R/classif_acc.R index 9d6e3ba..ca7ee7d 100644 --- a/R/classif_acc.R +++ b/R/classif_acc.R @@ -3,9 +3,9 @@ #' @details #' The Classification Accuracy is defined as #' \deqn{ -#' \frac{1}{n} \sum_{i=1}^n w_i \mathbf{1} \left( t_i = r_i \right), -#' }{1 / n * sum(wi * 1(ti = ri))} -#' where \eqn{w_i} are normalized weights for all observations \eqn{x_i}. +#' \sum_{i=1}^n w_i \mathbf{1} \left( t_i = r_i \right), +#' }{sum(wi * 1(ti = ri))} +#' where \eqn{w_i} are weights normalized to sum to 1 for all observations \eqn{x_i}. #' #' @templateVar mid acc #' @template classif_template diff --git a/man/acc.Rd b/man/acc.Rd index ab2f758..a59ba16 100644 --- a/man/acc.Rd +++ b/man/acc.Rd @@ -35,9 +35,9 @@ in multiclass classification tasks. \details{ The Classification Accuracy is defined as \deqn{ - \frac{1}{n} \sum_{i=1}^n w_i \mathbf{1} \left( t_i = r_i \right), -}{1 / n * sum(wi * 1(ti = ri))} -where \eqn{w_i} are normalized weights for all observations \eqn{x_i}. + \sum_{i=1}^n w_i \mathbf{1} \left( t_i = r_i \right), +}{sum(wi * 1(ti = ri))} +where \eqn{w_i} are weights normalized to sum to 1 for all observations \eqn{x_i}. } \section{Meta Information}{ From 3fe526be5a8893a2582910d3b14b972c49670ca0 Mon Sep 17 00:00:00 2001 From: mb706 Date: Thu, 17 Apr 2025 18:11:51 +0200 Subject: [PATCH 2/7] remove rsq-measures since we have rsq at home (i.e., mlr3) --- R/regr_rae.R | 27 --------------------------- R/regr_rrse.R | 31 ------------------------------- R/regr_rse.R | 31 ------------------------------- R/regr_rsq.R | 33 --------------------------------- 4 files changed, 122 deletions(-) delete mode 100644 R/regr_rae.R delete mode 100644 R/regr_rrse.R delete mode 100644 R/regr_rse.R delete mode 100644 R/regr_rsq.R diff --git a/R/regr_rae.R b/R/regr_rae.R deleted file mode 100644 index 079857a..0000000 --- a/R/regr_rae.R +++ /dev/null @@ -1,27 +0,0 @@ -#' @title Relative Absolute Error -#' -#' @details -#' The Relative Absolute Error is defined as \deqn{ -#' \frac{\sum_{i=1}^n \left| t_i - r_i \right|}{\sum_{i=1}^n \left| t_i - \bar{t} \right|}, -#' }{ -#' sum((t - r)^2) / sum((t - mean(t))^2), -#' } -#' where \eqn{\bar{t} = \sum_{i=1}^n t_i}. -#' This measure is undefined for constant \eqn{t}. -#' -#' Can be interpreted as absolute error of the predictions relative to a naive model predicting the mean. -#' -#' @templateVar mid rae -#' @template regr_template -#' -#' @inheritParams regr_params -#' @template regr_example -#' @export -rae = function(truth, response, na_value = NaN, ...) { - assert_regr(truth, response = response, na_value = na_value) - div(sum(.ae(truth, response)), sum(.ae(truth, mean(truth))), na_value) -} - - -#' @include measures.R -add_measure(rae, "Relative Absolute Error", "regr", 0, Inf, TRUE) diff --git a/R/regr_rrse.R b/R/regr_rrse.R deleted file mode 100644 index e13276d..0000000 --- a/R/regr_rrse.R +++ /dev/null @@ -1,31 +0,0 @@ -#' @title Root Relative Squared Error -#' -#' @details -#' The Root Relative Squared Error is defined as \deqn{ -#' \sqrt{\frac{\sum_{i=1}^n \left( t_i - r_i \right)^2}{\sum_{i=1}^n \left( t_i - \bar{t} \right)^2}}, -#' }{ -#' sqrt(sum((t - r)^2) / sum((t - mean(t))^2)), -#' } -#' where \eqn{\bar{t} = \sum_{i=1}^n t_i}. -#' -#' Can be interpreted as root of the squared error of the predictions relative to a naive model predicting the mean. -#' -#' This measure is undefined for constant \eqn{t}. -#' -#' @templateVar mid rrse -#' @template regr_template -#' -#' @inheritParams regr_params -#' @template regr_example -#' @export -rrse = function(truth, response, na_value = NaN, ...) { - assert_regr(truth, response = response, na_value = na_value) - v = var(truth) - if (v < TOL) { - return(na_value) - } - sqrt(sum(.se(truth, response)) / (v * (length(truth) - 1L))) -} - -#' @include measures.R -add_measure(rrse, "Root Relative Squared Error", "regr", 0, Inf, TRUE) diff --git a/R/regr_rse.R b/R/regr_rse.R deleted file mode 100644 index 08f0bf1..0000000 --- a/R/regr_rse.R +++ /dev/null @@ -1,31 +0,0 @@ -#' @title Relative Squared Error -#' -#' @details -#' The Relative Squared Error is defined as \deqn{ -#' \frac{\sum_{i=1}^n \left( t_i - r_i \right)^2}{\sum_{i=1}^n \left( t_i - \bar{t} \right)^2}, -#' }{ -#' sum((t - r)^2) / sum((t - mean(t))^2), -#' } -#' where \eqn{\bar{t} = \sum_{i=1}^n t_i}. -#' -#' Can be interpreted as squared error of the predictions relative to a naive model predicting the mean. -#' -#' This measure is undefined for constant \eqn{t}. -#' -#' @templateVar mid rse -#' @template regr_template -#' -#' @inheritParams regr_params -#' @template regr_example -#' @export -rse = function(truth, response, na_value = NaN, ...) { - assert_regr(truth, response = response, na_value = na_value) - v = var(truth) - if (v < TOL) { - return(na_value) - } - sum(.se(truth, response)) / (v * (length(truth) - 1L)) -} - -#' @include measures.R -add_measure(rse, "Relative Squared Error", "regr", 0, Inf, TRUE) diff --git a/R/regr_rsq.R b/R/regr_rsq.R deleted file mode 100644 index 02ec269..0000000 --- a/R/regr_rsq.R +++ /dev/null @@ -1,33 +0,0 @@ -#' @title R Squared -#' -#' @details -#' R Squared is defined as \deqn{ -#' 1 - \frac{\sum_{i=1}^n \left( t_i - r_i \right)^2}{\sum_{i=1}^n \left( t_i - \bar{t} \right)^2}, -#' }{ -#' 1 - sum((t - r)^2) / sum((t - mean(t))^2), -#' } -#' where \eqn{\bar{t} = \sum_{i=1}^n t_i}. -#' -#' Also known as coefficient of determination or explained variation. -#' Subtracts the [rse()] from 1, hence it compares the squared error of -#' the predictions relative to a naive model predicting the mean. -#' -#' This measure is undefined for constant \eqn{t}. -#' -#' @templateVar mid rsq -#' @template regr_template -#' -#' @inheritParams regr_params -#' @template regr_example -#' @export -rsq = function(truth, response, na_value = NaN, ...) { - assert_regr(truth, response = response, na_value = na_value) - v = var(truth) - if (v < TOL) { - return(na_value) - } - 1 - sum(.se(truth, response)) / (v * (length(truth) - 1L)) -} - -#' @include measures.R -add_measure(rsq, "R Squared", "regr", -Inf, 1, FALSE) From b4f86596ea1926d021c05e5bf0b3b4057664e218 Mon Sep 17 00:00:00 2001 From: mb706 Date: Thu, 17 Apr 2025 18:16:08 +0200 Subject: [PATCH 3/7] update NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index dd8d18e..9573db5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # mlr3measures (development version) +* BREAKIG CHANGE: removed `rse`, `rsq`, `rrse`, and `rae`. + # mlr3measures 1.0.0 * Added new measure `linex` (Linear-Exponential Loss). From 8dbb6590ca9443e3f9edfbcf6564923ac8e03605 Mon Sep 17 00:00:00 2001 From: mb706 Date: Thu, 17 Apr 2025 18:24:31 +0200 Subject: [PATCH 4/7] support more sample weights --- R/helper.R | 8 ++++++++ R/regr_sae.R | 15 +++++++++++---- R/regr_sse.R | 15 +++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/R/helper.R b/R/helper.R index 1b07607..3e1ad41 100644 --- a/R/helper.R +++ b/R/helper.R @@ -23,6 +23,14 @@ wmean = function(x, w) { # a better stats::weighted.mean sum(x * (w / sum(w))) } +wsum = function(x, w) { # sum(w * x) that asserts w and accepts NULL + if (is.null(w)) { + return(sum(x)) + } + assert_numeric(w, lower = 0, finite = TRUE, any.missing = FALSE, len = length(x)) + sum(x * w) +} + # confusion matrix cm = function(truth, response, positive = NULL) { if (!is.null(positive)) { diff --git a/R/regr_sae.R b/R/regr_sae.R index 28dda12..4d613ea 100644 --- a/R/regr_sae.R +++ b/R/regr_sae.R @@ -2,20 +2,27 @@ #' #' @details #' The Sum of Absolute Errors is defined as \deqn{ -#' \sum_{i=1}^n \left| t_i - r_i \right|. +#' \sum_{i=1}^n w_i \left| t_i - r_i \right|. #' }{ -#' sum(abs((t - r))). +#' sum(w * abs((t - r))). #' } +#' where \eqn{w_i} are unnormalized weights for each observation \eqn{x_i}, defaulting to 1. #' #' @templateVar mid sae #' @template regr_template #' +#' @param sample_weights (`numeric()`)\cr +#' Vector of non-negative and finite sample weights. +#' Must have the same length as `truth`. +#' Weights for this function are not normalized. +#' Defaults to sample weights 1. +#' #' @inheritParams regr_params #' @template regr_example #' @export -sae = function(truth, response, ...) { +sae = function(truth, response, sample_weights = NULL, ...) { assert_regr(truth, response = response) - sum(.ae(truth, response)) + sum(.ae(truth, response), sample_weights) } #' @include measures.R diff --git a/R/regr_sse.R b/R/regr_sse.R index 002a06a..ea94c80 100644 --- a/R/regr_sse.R +++ b/R/regr_sse.R @@ -2,20 +2,27 @@ #' #' @details #' The Sum of Squared Errors is defined as \deqn{ -#' \sum_{i=1}^n \left( t_i - r_i \right)^2. +#' \sum_{i=1}^n w_i \left( t_i - r_i \right)^2. #' }{ -#' sum((t - r)^2). +#' sum(w * (t - r)^2). #' } +#' where \eqn{w_i} are unnormalized weights for each observation \eqn{x_i}, defaulting to 1. #' #' @templateVar mid sse #' @template regr_template #' +#' @param sample_weights (`numeric()`)\cr +#' Vector of non-negative and finite sample weights. +#' Must have the same length as `truth`. +#' Weights for this function are not normalized. +#' Defaults to sample weights 1. +#' #' @inheritParams regr_params #' @template regr_example #' @export -sse = function(truth, response, ...) { +sse = function(truth, response, sample_weights = NULL, ...) { assert_regr(truth, response = response) - sum(.se(truth, response)) + wsum(.se(truth, response), sample_weights) } #' @include measures.R From 75c8d4e1d47d23b3a89c429a11bd1695a2349ffa Mon Sep 17 00:00:00 2001 From: mb706 Date: Thu, 17 Apr 2025 18:24:56 +0200 Subject: [PATCH 5/7] document() --- DESCRIPTION | 4 --- NAMESPACE | 4 --- man/ae.Rd | 4 --- man/ape.Rd | 4 --- man/bias.Rd | 4 --- man/ktau.Rd | 4 --- man/linex.Rd | 4 --- man/mae.Rd | 4 --- man/mape.Rd | 4 --- man/maxae.Rd | 4 --- man/maxse.Rd | 4 --- man/measures.Rd | 2 +- man/medae.Rd | 4 --- man/medse.Rd | 4 --- man/mse.Rd | 4 --- man/msle.Rd | 4 --- man/pbias.Rd | 4 --- man/pinball.Rd | 4 --- man/rae.Rd | 88 ----------------------------------------------- man/rmse.Rd | 4 --- man/rmsle.Rd | 4 --- man/rrse.Rd | 89 ----------------------------------------------- man/rse.Rd | 89 ----------------------------------------------- man/rsq.Rd | 91 ------------------------------------------------- man/sae.Rd | 17 +++++---- man/se.Rd | 4 --- man/sle.Rd | 4 --- man/smape.Rd | 4 --- man/srho.Rd | 4 --- man/sse.Rd | 17 +++++---- 30 files changed, 21 insertions(+), 464 deletions(-) delete mode 100644 man/rae.Rd delete mode 100644 man/rrse.Rd delete mode 100644 man/rse.Rd delete mode 100644 man/rsq.Rd diff --git a/DESCRIPTION b/DESCRIPTION index a4ea62d..9e01bd1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -78,12 +78,8 @@ Collate: 'regr_msle.R' 'regr_pbias.R' 'regr_pinball.R' - 'regr_rae.R' 'regr_rmse.R' 'regr_rmsle.R' - 'regr_rrse.R' - 'regr_rse.R' - 'regr_rsq.R' 'regr_sae.R' 'regr_se.R' 'regr_sle.R' diff --git a/NAMESPACE b/NAMESPACE index 531ce80..d6367c8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -48,13 +48,9 @@ export(pinball) export(ppv) export(prauc) export(precision) -export(rae) export(recall) export(rmse) export(rmsle) -export(rrse) -export(rse) -export(rsq) export(sae) export(se) export(sensitivity) diff --git a/man/ae.Rd b/man/ae.Rd index 8830349..66e23a8 100644 --- a/man/ae.Rd +++ b/man/ae.Rd @@ -59,12 +59,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/ape.Rd b/man/ape.Rd index e23bcc9..07eb00e 100644 --- a/man/ape.Rd +++ b/man/ape.Rd @@ -59,12 +59,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/bias.Rd b/man/bias.Rd index 948b0ce..c8e4259 100644 --- a/man/bias.Rd +++ b/man/bias.Rd @@ -71,12 +71,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/ktau.Rd b/man/ktau.Rd index 20d3993..26018b0 100644 --- a/man/ktau.Rd +++ b/man/ktau.Rd @@ -70,12 +70,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/linex.Rd b/man/linex.Rd index 41e00ce..9ff84ef 100644 --- a/man/linex.Rd +++ b/man/linex.Rd @@ -80,12 +80,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/mae.Rd b/man/mae.Rd index 50745c2..620e09e 100644 --- a/man/mae.Rd +++ b/man/mae.Rd @@ -70,12 +70,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/mape.Rd b/man/mape.Rd index 853464a..6a4cfcc 100644 --- a/man/mape.Rd +++ b/man/mape.Rd @@ -82,12 +82,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/maxae.Rd b/man/maxae.Rd index ed36d42..bf8312c 100644 --- a/man/maxae.Rd +++ b/man/maxae.Rd @@ -63,12 +63,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/maxse.Rd b/man/maxse.Rd index 10f5b3c..c441bd9 100644 --- a/man/maxse.Rd +++ b/man/maxse.Rd @@ -63,12 +63,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/measures.Rd b/man/measures.Rd index a26418e..d145f89 100644 --- a/man/measures.Rd +++ b/man/measures.Rd @@ -5,7 +5,7 @@ \alias{measures} \title{Measure Registry} \format{ -An object of class \code{environment} of length 65. +An object of class \code{environment} of length 61. } \usage{ measures diff --git a/man/medae.Rd b/man/medae.Rd index 8ae7f84..67c1eb7 100644 --- a/man/medae.Rd +++ b/man/medae.Rd @@ -63,12 +63,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/medse.Rd b/man/medse.Rd index ff470d6..d009266 100644 --- a/man/medse.Rd +++ b/man/medse.Rd @@ -63,12 +63,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/mse.Rd b/man/mse.Rd index 0c8450e..ca784bf 100644 --- a/man/mse.Rd +++ b/man/mse.Rd @@ -70,12 +70,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/msle.Rd b/man/msle.Rd index e7ca47f..c2b0373 100644 --- a/man/msle.Rd +++ b/man/msle.Rd @@ -75,12 +75,8 @@ Other Regression Measures: \code{\link{mse}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/pbias.Rd b/man/pbias.Rd index 2add0b1..bdb0758 100644 --- a/man/pbias.Rd +++ b/man/pbias.Rd @@ -75,12 +75,8 @@ Other Regression Measures: \code{\link{mse}()}, \code{\link{msle}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/pinball.Rd b/man/pinball.Rd index bfc6788..6ee8445 100644 --- a/man/pinball.Rd +++ b/man/pinball.Rd @@ -75,12 +75,8 @@ Other Regression Measures: \code{\link{mse}()}, \code{\link{msle}()}, \code{\link{pbias}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/rae.Rd b/man/rae.Rd deleted file mode 100644 index 2bd9d2a..0000000 --- a/man/rae.Rd +++ /dev/null @@ -1,88 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/regr_rae.R -\name{rae} -\alias{rae} -\title{Relative Absolute Error} -\usage{ -rae(truth, response, na_value = NaN, ...) -} -\arguments{ -\item{truth}{(\code{numeric()})\cr -True (observed) values. -Must have the same length as \code{response}.} - -\item{response}{(\code{numeric()})\cr -Predicted response values. -Must have the same length as \code{truth}.} - -\item{na_value}{(\code{numeric(1)})\cr -Value that should be returned if the measure is not defined for the input -(as described in the note). Default is \code{NaN}.} - -\item{...}{(\code{any})\cr -Additional arguments. Currently ignored.} -} -\value{ -Performance value as \code{numeric(1)}. -} -\description{ -Measure to compare true observed response with predicted response in regression tasks. -} -\details{ -The Relative Absolute Error is defined as \deqn{ - \frac{\sum_{i=1}^n \left| t_i - r_i \right|}{\sum_{i=1}^n \left| t_i - \bar{t} \right|}, -}{ - sum((t - r)^2) / sum((t - mean(t))^2), -} -where \eqn{\bar{t} = \sum_{i=1}^n t_i}. -This measure is undefined for constant \eqn{t}. - -Can be interpreted as absolute error of the predictions relative to a naive model predicting the mean. -} -\section{Meta Information}{ - -\itemize{ -\item Type: \code{"regr"} -\item Range: \eqn{[0, \infty)}{[0, Inf)} -\item Minimize: \code{TRUE} -\item Required prediction: \code{response} -} -} - -\examples{ -set.seed(1) -truth = 1:10 -response = truth + rnorm(10) -rae(truth, response) -} -\seealso{ -Other Regression Measures: -\code{\link{ae}()}, -\code{\link{ape}()}, -\code{\link{bias}()}, -\code{\link{ktau}()}, -\code{\link{linex}()}, -\code{\link{mae}()}, -\code{\link{mape}()}, -\code{\link{maxae}()}, -\code{\link{maxse}()}, -\code{\link{medae}()}, -\code{\link{medse}()}, -\code{\link{mse}()}, -\code{\link{msle}()}, -\code{\link{pbias}()}, -\code{\link{pinball}()}, -\code{\link{rmse}()}, -\code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, -\code{\link{sae}()}, -\code{\link{se}()}, -\code{\link{sle}()}, -\code{\link{smape}()}, -\code{\link{srho}()}, -\code{\link{sse}()} -} -\concept{Regression Measures} -\concept{regression_measure} diff --git a/man/rmse.Rd b/man/rmse.Rd index e35788c..019a39e 100644 --- a/man/rmse.Rd +++ b/man/rmse.Rd @@ -71,11 +71,7 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/rmsle.Rd b/man/rmsle.Rd index 0136c91..a356182 100644 --- a/man/rmsle.Rd +++ b/man/rmsle.Rd @@ -77,11 +77,7 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/rrse.Rd b/man/rrse.Rd deleted file mode 100644 index 39e5d8e..0000000 --- a/man/rrse.Rd +++ /dev/null @@ -1,89 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/regr_rrse.R -\name{rrse} -\alias{rrse} -\title{Root Relative Squared Error} -\usage{ -rrse(truth, response, na_value = NaN, ...) -} -\arguments{ -\item{truth}{(\code{numeric()})\cr -True (observed) values. -Must have the same length as \code{response}.} - -\item{response}{(\code{numeric()})\cr -Predicted response values. -Must have the same length as \code{truth}.} - -\item{na_value}{(\code{numeric(1)})\cr -Value that should be returned if the measure is not defined for the input -(as described in the note). Default is \code{NaN}.} - -\item{...}{(\code{any})\cr -Additional arguments. Currently ignored.} -} -\value{ -Performance value as \code{numeric(1)}. -} -\description{ -Measure to compare true observed response with predicted response in regression tasks. -} -\details{ -The Root Relative Squared Error is defined as \deqn{ - \sqrt{\frac{\sum_{i=1}^n \left( t_i - r_i \right)^2}{\sum_{i=1}^n \left( t_i - \bar{t} \right)^2}}, -}{ - sqrt(sum((t - r)^2) / sum((t - mean(t))^2)), -} -where \eqn{\bar{t} = \sum_{i=1}^n t_i}. - -Can be interpreted as root of the squared error of the predictions relative to a naive model predicting the mean. - -This measure is undefined for constant \eqn{t}. -} -\section{Meta Information}{ - -\itemize{ -\item Type: \code{"regr"} -\item Range: \eqn{[0, \infty)}{[0, Inf)} -\item Minimize: \code{TRUE} -\item Required prediction: \code{response} -} -} - -\examples{ -set.seed(1) -truth = 1:10 -response = truth + rnorm(10) -rrse(truth, response) -} -\seealso{ -Other Regression Measures: -\code{\link{ae}()}, -\code{\link{ape}()}, -\code{\link{bias}()}, -\code{\link{ktau}()}, -\code{\link{linex}()}, -\code{\link{mae}()}, -\code{\link{mape}()}, -\code{\link{maxae}()}, -\code{\link{maxse}()}, -\code{\link{medae}()}, -\code{\link{medse}()}, -\code{\link{mse}()}, -\code{\link{msle}()}, -\code{\link{pbias}()}, -\code{\link{pinball}()}, -\code{\link{rae}()}, -\code{\link{rmse}()}, -\code{\link{rmsle}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, -\code{\link{sae}()}, -\code{\link{se}()}, -\code{\link{sle}()}, -\code{\link{smape}()}, -\code{\link{srho}()}, -\code{\link{sse}()} -} -\concept{Regression Measures} -\concept{regression_measure} diff --git a/man/rse.Rd b/man/rse.Rd deleted file mode 100644 index 6bc590a..0000000 --- a/man/rse.Rd +++ /dev/null @@ -1,89 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/regr_rse.R -\name{rse} -\alias{rse} -\title{Relative Squared Error} -\usage{ -rse(truth, response, na_value = NaN, ...) -} -\arguments{ -\item{truth}{(\code{numeric()})\cr -True (observed) values. -Must have the same length as \code{response}.} - -\item{response}{(\code{numeric()})\cr -Predicted response values. -Must have the same length as \code{truth}.} - -\item{na_value}{(\code{numeric(1)})\cr -Value that should be returned if the measure is not defined for the input -(as described in the note). Default is \code{NaN}.} - -\item{...}{(\code{any})\cr -Additional arguments. Currently ignored.} -} -\value{ -Performance value as \code{numeric(1)}. -} -\description{ -Measure to compare true observed response with predicted response in regression tasks. -} -\details{ -The Relative Squared Error is defined as \deqn{ - \frac{\sum_{i=1}^n \left( t_i - r_i \right)^2}{\sum_{i=1}^n \left( t_i - \bar{t} \right)^2}, -}{ - sum((t - r)^2) / sum((t - mean(t))^2), -} -where \eqn{\bar{t} = \sum_{i=1}^n t_i}. - -Can be interpreted as squared error of the predictions relative to a naive model predicting the mean. - -This measure is undefined for constant \eqn{t}. -} -\section{Meta Information}{ - -\itemize{ -\item Type: \code{"regr"} -\item Range: \eqn{[0, \infty)}{[0, Inf)} -\item Minimize: \code{TRUE} -\item Required prediction: \code{response} -} -} - -\examples{ -set.seed(1) -truth = 1:10 -response = truth + rnorm(10) -rse(truth, response) -} -\seealso{ -Other Regression Measures: -\code{\link{ae}()}, -\code{\link{ape}()}, -\code{\link{bias}()}, -\code{\link{ktau}()}, -\code{\link{linex}()}, -\code{\link{mae}()}, -\code{\link{mape}()}, -\code{\link{maxae}()}, -\code{\link{maxse}()}, -\code{\link{medae}()}, -\code{\link{medse}()}, -\code{\link{mse}()}, -\code{\link{msle}()}, -\code{\link{pbias}()}, -\code{\link{pinball}()}, -\code{\link{rae}()}, -\code{\link{rmse}()}, -\code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rsq}()}, -\code{\link{sae}()}, -\code{\link{se}()}, -\code{\link{sle}()}, -\code{\link{smape}()}, -\code{\link{srho}()}, -\code{\link{sse}()} -} -\concept{Regression Measures} -\concept{regression_measure} diff --git a/man/rsq.Rd b/man/rsq.Rd deleted file mode 100644 index 79cc86e..0000000 --- a/man/rsq.Rd +++ /dev/null @@ -1,91 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/regr_rsq.R -\name{rsq} -\alias{rsq} -\title{R Squared} -\usage{ -rsq(truth, response, na_value = NaN, ...) -} -\arguments{ -\item{truth}{(\code{numeric()})\cr -True (observed) values. -Must have the same length as \code{response}.} - -\item{response}{(\code{numeric()})\cr -Predicted response values. -Must have the same length as \code{truth}.} - -\item{na_value}{(\code{numeric(1)})\cr -Value that should be returned if the measure is not defined for the input -(as described in the note). Default is \code{NaN}.} - -\item{...}{(\code{any})\cr -Additional arguments. Currently ignored.} -} -\value{ -Performance value as \code{numeric(1)}. -} -\description{ -Measure to compare true observed response with predicted response in regression tasks. -} -\details{ -R Squared is defined as \deqn{ - 1 - \frac{\sum_{i=1}^n \left( t_i - r_i \right)^2}{\sum_{i=1}^n \left( t_i - \bar{t} \right)^2}, -}{ - 1 - sum((t - r)^2) / sum((t - mean(t))^2), -} -where \eqn{\bar{t} = \sum_{i=1}^n t_i}. - -Also known as coefficient of determination or explained variation. -Subtracts the \code{\link[=rse]{rse()}} from 1, hence it compares the squared error of -the predictions relative to a naive model predicting the mean. - -This measure is undefined for constant \eqn{t}. -} -\section{Meta Information}{ - -\itemize{ -\item Type: \code{"regr"} -\item Range: \eqn{(-\infty, 1]}{(-Inf, 1]} -\item Minimize: \code{FALSE} -\item Required prediction: \code{response} -} -} - -\examples{ -set.seed(1) -truth = 1:10 -response = truth + rnorm(10) -rsq(truth, response) -} -\seealso{ -Other Regression Measures: -\code{\link{ae}()}, -\code{\link{ape}()}, -\code{\link{bias}()}, -\code{\link{ktau}()}, -\code{\link{linex}()}, -\code{\link{mae}()}, -\code{\link{mape}()}, -\code{\link{maxae}()}, -\code{\link{maxse}()}, -\code{\link{medae}()}, -\code{\link{medse}()}, -\code{\link{mse}()}, -\code{\link{msle}()}, -\code{\link{pbias}()}, -\code{\link{pinball}()}, -\code{\link{rae}()}, -\code{\link{rmse}()}, -\code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{sae}()}, -\code{\link{se}()}, -\code{\link{sle}()}, -\code{\link{smape}()}, -\code{\link{srho}()}, -\code{\link{sse}()} -} -\concept{Regression Measures} -\concept{regression_measure} diff --git a/man/sae.Rd b/man/sae.Rd index f735614..ddb8dd1 100644 --- a/man/sae.Rd +++ b/man/sae.Rd @@ -4,7 +4,7 @@ \alias{sae} \title{Sum of Absolute Errors} \usage{ -sae(truth, response, ...) +sae(truth, response, sample_weights = NULL, ...) } \arguments{ \item{truth}{(\code{numeric()})\cr @@ -15,6 +15,12 @@ Must have the same length as \code{response}.} Predicted response values. Must have the same length as \code{truth}.} +\item{sample_weights}{(\code{numeric()})\cr +Vector of non-negative and finite sample weights. +Must have the same length as \code{truth}. +Weights for this function are not normalized. +Defaults to sample weights 1.} + \item{...}{(\code{any})\cr Additional arguments. Currently ignored.} } @@ -26,10 +32,11 @@ Measure to compare true observed response with predicted response in regression } \details{ The Sum of Absolute Errors is defined as \deqn{ - \sum_{i=1}^n \left| t_i - r_i \right|. + \sum_{i=1}^n w_i \left| t_i - r_i \right|. }{ - sum(abs((t - r))). + sum(w * abs((t - r))). } +where \eqn{w_i} are unnormalized weights for each observation \eqn{x_i}, defaulting to 1. } \section{Meta Information}{ @@ -64,12 +71,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{se}()}, \code{\link{sle}()}, \code{\link{smape}()}, diff --git a/man/se.Rd b/man/se.Rd index da17af8..c7426ff 100644 --- a/man/se.Rd +++ b/man/se.Rd @@ -60,12 +60,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{sle}()}, \code{\link{smape}()}, diff --git a/man/sle.Rd b/man/sle.Rd index 439b2c1..ce0b9fb 100644 --- a/man/sle.Rd +++ b/man/sle.Rd @@ -59,12 +59,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{smape}()}, diff --git a/man/smape.Rd b/man/smape.Rd index 294b6a7..1090cc3 100644 --- a/man/smape.Rd +++ b/man/smape.Rd @@ -70,12 +70,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/srho.Rd b/man/srho.Rd index 8b947e7..9aa7d5e 100644 --- a/man/srho.Rd +++ b/man/srho.Rd @@ -67,12 +67,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, diff --git a/man/sse.Rd b/man/sse.Rd index 52e8b2c..df9ab83 100644 --- a/man/sse.Rd +++ b/man/sse.Rd @@ -4,7 +4,7 @@ \alias{sse} \title{Sum of Squared Errors} \usage{ -sse(truth, response, ...) +sse(truth, response, sample_weights = NULL, ...) } \arguments{ \item{truth}{(\code{numeric()})\cr @@ -15,6 +15,12 @@ Must have the same length as \code{response}.} Predicted response values. Must have the same length as \code{truth}.} +\item{sample_weights}{(\code{numeric()})\cr +Vector of non-negative and finite sample weights. +Must have the same length as \code{truth}. +Weights for this function are not normalized. +Defaults to sample weights 1.} + \item{...}{(\code{any})\cr Additional arguments. Currently ignored.} } @@ -26,10 +32,11 @@ Measure to compare true observed response with predicted response in regression } \details{ The Sum of Squared Errors is defined as \deqn{ - \sum_{i=1}^n \left( t_i - r_i \right)^2. + \sum_{i=1}^n w_i \left( t_i - r_i \right)^2. }{ - sum((t - r)^2). + sum(w * (t - r)^2). } +where \eqn{w_i} are unnormalized weights for each observation \eqn{x_i}, defaulting to 1. } \section{Meta Information}{ @@ -64,12 +71,8 @@ Other Regression Measures: \code{\link{msle}()}, \code{\link{pbias}()}, \code{\link{pinball}()}, -\code{\link{rae}()}, \code{\link{rmse}()}, \code{\link{rmsle}()}, -\code{\link{rrse}()}, -\code{\link{rse}()}, -\code{\link{rsq}()}, \code{\link{sae}()}, \code{\link{se}()}, \code{\link{sle}()}, From e4cf3d0cea3be34371ff95428343c0d847a9ad24 Mon Sep 17 00:00:00 2001 From: mb706 Date: Thu, 17 Apr 2025 16:29:19 +0000 Subject: [PATCH 6/7] Update NEWS.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- NEWS.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9573db5..aaea275 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,6 @@ # mlr3measures (development version) -* BREAKIG CHANGE: removed `rse`, `rsq`, `rrse`, and `rae`. - +* BREAKING CHANGE: removed `rse`, `rsq`, `rrse`, and `rae`. # mlr3measures 1.0.0 * Added new measure `linex` (Linear-Exponential Loss). From 1b62ec7fc921265b2dea0fefd1020723b0d523d7 Mon Sep 17 00:00:00 2001 From: mb706 Date: Thu, 17 Apr 2025 19:19:31 +0200 Subject: [PATCH 7/7] adjust tests --- NEWS.md | 1 + tests/testthat/test_regr.R | 16 ---------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9573db5..28a9a95 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # mlr3measures (development version) * BREAKIG CHANGE: removed `rse`, `rsq`, `rrse`, and `rae`. +* Measures `sae` and `sse` gain `sample_weights` (unnormalized weights). # mlr3measures 1.0.0 diff --git a/tests/testthat/test_regr.R b/tests/testthat/test_regr.R index 7beb4f4..0a1ab55 100644 --- a/tests/testthat/test_regr.R +++ b/tests/testthat/test_regr.R @@ -70,22 +70,6 @@ test_that("tests from Metrics", { expect_equal(rmsle(c(exp(5) - 1), c(exp(1) - 1)), 4) - expect_equal(rae(0:10, 30:40), 11) - expect_equal(rae(seq(0, 2, 0.5), seq(0, 2, 0.5)), 0.0) - expect_equal(rae(1:4, c(1, 2, 3, 5)), 0.25) - - expect_equal(rrse(0:10, 2:12), sqrt(0.4)) - expect_equal(rrse(seq(0, 2, 0.5), seq(0, 2, 0.5)), 0.0) - expect_equal(rrse(1:4, c(1, 2, 3, 5)), sqrt(0.2)) - - expect_equal(rse(0:10, 2:12), 0.4) - expect_equal(rse(seq(0, 2, 0.5), seq(0, 2, 0.5)), 0.0) - expect_equal(rse(1:4, c(1, 2, 3, 5)), 0.2) - - expect_equal(rsq(0:10, 2:12), 0.6) - expect_equal(rsq(seq(0, 2, 0.5), seq(0, 2, 0.5)), 1.0) - expect_equal(rsq(1:4, c(1, 2, 3, 5)), 0.8) - expect_equal(pinball(1:3, 1:3), 0) expect_equal(pinball(1:3, c(0, 2, 3)), 1 / 6) expect_equal(pinball(1:3, c(1, 2, 4)), 1 / 6)