Skip to contents

This function computes the mean squared logarithmic error.

Usage

mean_squared_log_error(
  true,
  pred,
  weights = NULL,
  multi = c("average", "sum", "raw"),
  root = FALSE,
  rweights = NULL
)

Arguments

true

a vector (or a matrix) of observed values. If a matrix is provided, a multi-response is assumed

pred

a vector (or a matrix) of predicted values

weights

observation weights

multi

what to do when response has multiple output values

average

errors of multiple outputs are averaged to get a single value for each observation

sum

errors of multiple outputs are summed up to get a single value for each observation

raw

returns a vector containing one error for each output

root

logical, whether to return the MSLE or the root mean squared logarithmic error (RMSLE)

rweights

response weights

Value

the mean squared error, a positive double or a vector of positive double values, one for each response, if response has multiple output values and multi = "raw"

Details

The mean squared logarithmic error (MSLE) is a measure of errors based on squared logarithmic losses. This metric is commonly preferred (e.g. over the MSE) when

  • Under-predicted estimates are more penalised than over-predicted ones.

  • Huge differences in the predicted and true values aren't to be penalised (when both are huge numbers).

The MSLE estimated over n observations is defined as

$$MSLE(y,\hat{y}) = \frac{1}{n}\sum_{i=1}^{n} (log(1 + y_{i}) - log(1 + \hat{y}_{i}))^{2}$$

where \(log\) is the natural logarithm, \(y_{i}\) is the true value of the \(i\)-th sample and \(\hat{y}_{i}\) is the predicted value. If observation weights are provided, then the weighted mean absolute error is computed as

$$wMSLE(w,y,\hat{y}) = \frac{1}{\sum_{i=1}^{n} w_{i}}\sum_{i=1}^{n} w_{i} * (log(1 + y_{i}) - log(1 + \hat{y}_{i}))^{2}$$

where \(w_{i}\) is the weighting factor assigned to the \(i\)-th observation.

The best possible score is zero.

Author

Alessandro Barberis