Root Mean Squared Logarithmic Error

rmsle.numeric R Documentation

Description

The rmsle()-function computes the root mean squared logarithmic error between the observed and predicted <numeric> vectors. The weighted.rmsle() function computes the weighted root mean squared logarithmic error.

Usage

## S3 method for class 'numeric'
rmsle(actual, predicted, ...)

## S3 method for class 'numeric'
weighted.rmsle(actual, predicted, w, ...)

## Generic S3 method
rmsle(
 actual,
 predicted,
 ...
)

## Generic S3 method
weighted.rmsle(
 actual,
 predicted,
 w,
 ...
)

Arguments

actual

A <numeric>-vector of length n. The observed (continuous) response variable.

predicted

A <numeric>-vector of length n. The estimated (continuous) response variable.

Arguments passed into other methods.

w

A <numeric>-vector of length n. The weight assigned to each observation in the data.

Value

A <numeric> vector of length 1.

Definition

The metric is calculated as,

1nin(log(1+yi)log(1+υi))2

Where yi and υi are the actual and predicted values respectively.

Examples

# 1) fit a linear
# regression
model <- lm(
  mpg ~ .,
  data = mtcars
)

# 1.1) define actual
# and predicted values
# to measure performance
actual    <- mtcars$mpg
predicted <- fitted(model)


# 2) evaluate in-sample model
# performance using Root Mean Squared Logarithmic Error (RMSLE)
cat(
  "Root Mean Squared Logarithmic Error", rmsle(
    actual    = actual,
    predicted = predicted,
  ),
  "Root Mean Squared Logarithmic Error (weighted)", weighted.rmsle(
    actual    = actual,
    predicted = predicted,
    w         = mtcars$mpg/mean(mtcars$mpg)
  ),
  sep = "\n"
)