## S3 method for class 'numeric'
rmsle(actual, predicted, ...)
## S3 method for class 'numeric'
weighted.rmsle(actual, predicted, w, ...)
rmsle(...)
weighted.rmsle(...)
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
Arguments
actual
|
A |
predicted
|
A |
…
|
Arguments passed into other methods. |
w
|
A |
Value
A <numeric>
vector of length 1.
Calculation
The metric is calculated as,
\[ \sqrt{\frac{1}{n} \sum_i^n (\log(1 + y_i) - \log(1 + \upsilon_i))^2} \]
Where \(y_i\) and \(\upsilon_i\) are the actual
and predicted
values respectively.
Examples
# 1) fit a linear
# regression
<- lm(
model ~ .,
mpg data = mtcars
)
# 1.1) define actual
# and predicted values
# to measure performance
<- mtcars$mpg
actual <- fitted(model)
predicted
# 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"
)