## S3 method for class 'numeric'
smape(actual, predicted, ...)
## S3 method for class 'numeric'
weighted.smape(actual, predicted, w, ...)
## Generic S3 method
smape(
actual,
predicted,
...
)
## Generic S3 method
weighted.smape(
actual,
predicted,
w,
... )
Symmetric Mean Absolute Percentage Error
smape.numeric | R Documentation |
Description
The smape()
-function computes the symmetric mean absolute percentage error between the observed and predicted <numeric>
vectors. The weighted.smape()
function computes the weighted symmetric mean absolute percentage error.
Usage
Arguments
actual
|
A |
predicted
|
A |
…
|
Arguments passed into other methods. |
w
|
A |
Value
A <numeric>
vector of length 1.
Definition
The metric is calculated as follows,
\[ \sum_i^n \frac{1}{n} \frac{|y_i - \upsilon_i|}{\frac{|y_i|+|\upsilon_i|}{2}} \]
where \(y_i\) and \(\upsilon_i\) is 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 Symmetric Mean Absolute Percentage Error (MAPE)
cat(
"Symmetric Mean Absolute Percentage Error", mape(
actual = actual,
predicted = predicted,
),"Symmetric Mean Absolute Percentage Error (weighted)", weighted.mape(
actual = actual,
predicted = predicted,
w = mtcars$mpg/mean(mtcars$mpg)
),sep = "\n"
)