How to use MLmetrics package In R Language
In R, the MLmetrics package provides us the MAPE() function using which we can calculate the MAPE in R. This function has the following syntax:
Syntax: MAPE(Ft, At)
Parameters:
Here,
- Ft: It represent forecasted values
- At: It represents actual values
Example:
R
# Create a dataframe dataframe <- data.frame (At= c (15, 40, 41, 32, 48, 28, 21, 47, 36, 37, 11, 14), Ft= c (32, 41, 43, 54, 66, 51, 46, 45, 37, 33, 25, 26)) # Print the dataframe dataframe |
Output:
Now to find out the MAPE of the above data frame, we can use MAPE() function:
R
# Import library library ( "MLmetrics" ) # Create a dataframe dataframe <- data.frame (At= c (15, 40, 41, 32, 48, 28, 21, 47, 36, 37, 11, 14), Ft= c (32, 41, 43, 54, 66, 51, 46, 45, 37, 33, 25, 26)) # Compute MAPE MAPE (dataframe$Ft, dataframe$At) |
Output:
Hence, the MAPE value comes out to be equal to 54.915 %.
How to Calculate MAPE in R
In this article, we are going to see how to calculate MAPE in R Programming Language.