In this vignette, a brief overview of the regression metrics in {SLmetrics} is provided.
The regression interface is based on [numeric] vectors and uses
foo.numeric()
and weighted.foo.numeric()
methods for unweighted and weighted regression metrics,
respectively.
Throughout this vignette, the following data will be used:
# 1) seed
set.seed(1903)
# 2) actual values
actual <- rnorm(
n = 100
)
# 3) predicted values
predicted <- actual + rnorm(n = 100)
# 4) sample weights
weights <- runif(
n = length(actual)
)
Assume that the predicted
values come from a trained
machine learning model. This vignette introduces a subset of the metrics
available in {SLmetrics}; see the online documentation for
more details and other metrics.
One of the most common metrics for regression tasks is the root mean squared error (RMSE) which can be computed with or without sample weights:
# 1) calculate unweighted RMSE
rmse(
actual = actual,
predicted = predicted
)
#> [1] 0.9085512
# 2) calculate weighted RMSE
weighted.rmse(
actual = actual,
predicted = predicted,
w = weights
)
#> [1] 0.9368692
Another metric is the relative root mean squared error (RRMSE). It applies a normalization factor to the RMSE, which can help compare errors across datasets with different scales. The RRMSE can be computed with three possible normalization methods:
# 1) calculate RRMSE
# with mean normalization
rrmse(
actual = actual,
predicted = predicted,
normalization = 0
)
#> [1] 6.935011
# 2) calculate RRSME
# with range normalization
rrmse(
actual = actual,
predicted = predicted,
normalization = 1
)
#> [1] 0.1711166
# 3) calculate RRSME
# with IQR normalization
rrmse(
actual = actual,
predicted = predicted,
normalization = 2
)
#> [1] 0.7002328
The parameter normalization
determines the normalization
factor of the RMSE;
max
-
min
)The interface for all regression metrics in {SLmetrics} follows the same basic signature: two numeric vectors (actual and predicted) and, optionally, sample weights (w) or other metric-specific parameters.