## S3 method for class 'numeric'
mpe(actual, predicted, ...)
## S3 method for class 'numeric'
weighted.mpe(actual, predicted, w, ...)
mpe(...)
weighted.mpe(...)
mean percentage error
mpe.numeric | R Documentation |
Description
The mpe()
-function computes the mean percentage error between the observed and predicted <numeric>
vectors. The weighted.mpe()
function computes the weighted mean percentage 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,
\[ \frac{1}{n} \sum_i^n \frac{y_i - \upsilon_i}{y_i} \]
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 Mean Percentage Error (MPE)
cat(
"Mean Percentage Error", mpe(
actual = actual,
predicted = predicted,
),"Mean Percentage Error (weighted)", weighted.mpe(
actual = actual,
predicted = predicted,
w = mtcars$mpg/mean(mtcars$mpg)
),sep = "\n"
)