Mean absolute percentage error between arrays (2024)

Mean absolute percentage error between arrays

Since R2022b

collapse all in page

Syntax

E = mape(F,A)

E = mape(F,A,"all")

E = mape(F,A,dim)

E = mape(F,A,vecdim)

E = mape(___,nanflag)

E = mape(___,zeroflag)

E = mape(___,Weights=W)

Description

example

E = mape(F,A) returns the mean absolute percentage error (MAPE) between the forecast (predicted) array F and the actual (observed) array A.

  • F and A must either be the same size or have sizes that are compatible.

  • If F and A are vectors of the same size, then E is a scalar.

  • If F-A is a matrix, then E is a row vector containing the MAPE for each column.

  • If F and A are multidimensional arrays, then E contains the MAPE computed along the first array dimension of size greater than 1, with elements treated as vectors. The size of E in this dimension is 1, while the sizes of all other dimensions are the same as in F-A.

E = mape(F,A,"all") returns the MAPE of all elements in F and A.

example

E = mape(F,A,dim) operates along dimension dim. For example, if F and A are matrices, then mape(F,A,2) operates on the elements in each row and returns a column vector containing the MAPE of each row.

example

E = mape(F,A,vecdim) operates along the dimensions specified in the vector vecdim. For example, if F and A are matrices, then mape(F,A,[1 2]) operates on all the elements in F and A because every element of a matrix is contained in the array slice defined by dimensions 1 and 2.

example

E = mape(___,nanflag) specifies whether to include or omit NaN values in F and A for any of the previous syntaxes. For example, mape(F,A,"omitnan") ignores NaN values when computing the MAPE. By default, mape includes NaN values.

example

E = mape(___,zeroflag) specifies whether to include or omit zero values in A. For example, mape(F,A,"includezero") includes the zeros in the calculation, while mape(F,A,"omitzero") ignores them.

example

E = mape(___,Weights=W) specifies a weighting scheme W and returns the weighted MAPE.

Examples

collapse all

MAPE of Two Forecasts

Open Live Script

Create two column vectors of forecast (predicted) data and one column vector of actual (observed) data.

F1 = [1; 10; 9];F2 = [2; 5; 10];A = [1; 9; 10];

Compute the MAPE between each forecast and the actual data.

E1 = mape(F1,A)
E1 = 7.0370
E2 = mape(F2,A)
E2 = 48.1481

Alternatively, create a matrix containing both forecasts and compute the MAPE between each forecast and the actual data in one command.

F = 3×2 1 2 10 5 9 10
E = mape(F,A)
E = 1×2 7.0370 48.1481

The first element of E is the MAPE between the first forecast column and the actual data. The second element of E is the MAPE between the second forecast column and the actual data.

MAPE of Matrix Rows

Open Live Script

Create a matrix of forecast data and a matrix of actual data.

F = [17 19; 1 6; 16 15];A = [17 25; 3 4; 16 13];

Compute the MAPE between the forecast and the actual data across each row by specifying the operating dimension as 2. The smallest MAPE corresponds to the MAPE between the third rows of the forecast data and actual data.

E = mape(F,A,2)
E = 3×1 12.0000 58.3333 7.6923

MAPE of Array Pages

Open Live Script

Create a 3-D array with pages containing forecast data and a matrix of actual data.

F(:,:,1) = [2 4; -2 1];F(:,:,2) = [4 4; 8 -3];A = [6 7; 1 4];

Compute the MAPE between the predicted data in each page of the forecast array and the actual data matrix by specifying a vector of operating dimensions 1 and 2.

E = mape(F,A,[1 2])
E = E(:,:,1) = 121.1310E(:,:,2) = 237.7976

The first page of E contains the MAPE between the first page of F and the matrix A. The second page of E contains the MAPE between the second page of F and the matrix A.

MAPE Excluding Missing Values

Open Live Script

Create a matrix of forecast data and a matrix of actual data containing NaN values.

F = [17 19 3; 6 16 NaN];A = [17 25 NaN; 4 16 NaN];

Compute the MAPE between the forecast and the actual data, ignoring NaN values. For columns that contain all NaN values in F or A, the MAPE is NaN.

E = mape(F,A,"omitnan")
E = 1×3 25 12 NaN

MAPE Excluding Zeros

Open Live Script

Create a row vector of forecast data and a row vector of actual data containing a zero.

F = [1 6 10 5];A = [2 6 0 3];

Compute the MAPE between the forecast and the actual data.

E = mape(F,A)
E = Inf

Because zero values in A are included in the MAPE calculation by default, the result is Inf. Ignore the zero in the actual data by specifying "omitzero". Now, the function computes the MAPE for only the first, second, and fourth columns of the input data.

Eomit = mape(F,A,"omitzero")
Eomit = 38.8889

Specify MAPE Weight Vector

Open Live Script

Create a forecast column vector and an actual column vector.

F = [2; 10; 13];A = [1; 9; 10];

Compute the MAPE between the forecast and actual data according to a weighting scheme specified by W.

W = [0.5; 0.25; 0.25];E = mape(F,A,Weights=W)
E = 60.2778

Input Arguments

collapse all

FForecast array
vector | matrix | multidimensional array

Forecast or predicted array, specified as a vector, matrix, or multidimensional array.

Inputs F and A must either be the same size or have sizes that are compatible. For example, F is an m-by-n matrix and A is a 1-by-n row vector. For more information, see Compatible Array Sizes for Basic Operations.

Data Types: single | double
Complex Number Support: Yes

AActual array
vector | matrix | multidimensional array

Actual or observed array, specified as a vector, matrix, or multidimensional array.

Inputs F and A must either be the same size or have sizes that are compatible. For example, F is an m-by-n matrix and A is a 1-by-n row vector. For more information, see Compatible Array Sizes for Basic Operations.

Data Types: single | double
Complex Number Support: Yes

dimDimension to operate along
positive integer scalar

Dimension to operate along, specified as a positive integer scalar. If you do not specify the dimension, then the default is the first array dimension of size greater than 1.

The size of E in the operating dimension is 1. All other dimensions of E have the same size as the result of F-A.

For example, consider four forecasts in a 3-by-4 matrix, F, and actual data in a 3-by-1 column vector, A:

  • mape(F,A,1) computes the MAPE of the elements in each column and returns a 1-by-4 row vector.

    The size of E in the operating dimension is 1. The difference of F and A is a 3-by-4 matrix. The size of E in the nonoperating dimension is the same as the second dimension of F-A, which is 4. The overall size of E becomes 1-by-4.

  • mape(F,A,2) computes the MAPE of the elements in each row and returns a 3-by-1 column vector.

    The size of E in the operating dimension is 1. The difference of F and A is a 3-by-4 matrix. The size of E in the nonoperating dimension is the same as the first dimension of F-A, which is 3. The overall size of E becomes 3-by-1.

vecdimVector of dimensions to operate along
vector of positive integers

Vector of dimensions to operate along, specified as a vector of positive integers. Each element represents a dimension of the input arrays. The size of E in the operating dimensions is 1. All other dimensions of E have the same size as the result of F-A.

For example, consider forecasts in a 2-by-3-by-3 array, F, and actual data in a 1-by-3 row vector, A. mape(F,A,[1 2]) computes the MAPE over each page of F and returns a 1-by-1-by-3 array. The size of E in the operating dimensions is 1. The difference of F and A is a 2-by-3-by-3 array. The size of E in the nonoperating dimension is the same as the third dimension of F-A, which is 3.

nanflagMissing value condition
"includemissing" (default) | "includenan" | "omitmissing" | "omitnan"

Missing value condition, specified as one of these values:

  • "includemissing" or "includenan" — Include NaN values in the input arrays when computing the MAPE. If any element in the operating dimension is NaN, then the corresponding element in E is NaN. "includemissing" and "includenan" have the same behavior.

  • "omitmissing" or "omitnan" — Ignore NaN values in the input arrays when computing the MAPE. If all elements in the operating dimension are NaN in F, A, or W, then the corresponding elements in E are NaN. "omitmissing" and "omitnan" have the same behavior.

zeroflagZero condition
"includezero" (default) | "omitzero"

Zero condition, specified as one of these values:

  • "includezero" — Include zeros in A when computing the MAPE. If A contains one or more zeros, then E is Inf.

  • "omitzero" — Ignore zeros in A when computing the MAPE. Small nonzero values of A that would result in a MAPE of Inf are also ignored. If all elements of A are ignored, then E is NaN.

WWeighting scheme
vector | matrix | multidimensional array

Weighting scheme, specified as a vector, matrix, or multidimensional array. The elements of W must be nonnegative.

If W is a vector, it must have the same length as the operating dimension or must have the same size as F-A. If W is a matrix or multidimensional array, it must have the same size as F, A, or F-A.

You cannot specify this argument if you specify vecdim or "all".

Data Types: double | single

More About

collapse all

Mean Absolute Percentage Error

For a forecast array F and actual array A made up of n scalar observations, the mean absolute percentage error is defined as

E=1ni=1n|AiFiAi|×100

with the summation performed along the specified dimension. When F or A is complex, mape computes the mean absolute percentage error using the complex magnitude of (F-A)./A.

Weighted Mean Absolute Percentage Error

For a forecast array F and actual array A made up of n scalar observations and weighting scheme W, the weighted mean absolute percentage error is defined as

EW=i=1nWi|AiFiAi|×100i=1nWi

with the summation performed along the specified dimension.

Tips

  • Zeros or small nonzero values in the actual data A might indicate that MAPE is not the appropriate metric to measure error for F and A.

Extended Capabilities

This function fully supports tall arrays. Formore information, see Tall Arrays.

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced in R2022b

expand all

Include or omit missing values in the input arrays when computing the MAPE by using the "includemissing" or "omitmissing" options. These options have the same behavior as the "includenan" and "omitnan" options, respectively.

Generate C or C++ code for the mape function.

See Also

rmse | mean | abs

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Mean absolute percentage error between arrays (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Mean absolute percentage error between arrays (2024)
Top Articles
Behind the Scenes: How K-Guard Gutters Are Made | One Stop Home Improvement
K-Guard Gutters | One Stop Home Improvement
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Nehemiah 4:1–23
Mountain Dew Bennington Pontoon
Crime Scene Photos West Memphis Three
Cvs Devoted Catalog
biBERK Business Insurance Provides Essential Insights on Liquor Store Risk Management and Insurance Considerations
Cars For Sale Tampa Fl Craigslist
Pro Groom Prices – The Pet Centre
Summoners War Update Notes
Trini Sandwich Crossword Clue
Washington Poe en Tilly Bradshaw 1 - Brandoffer, M.W. Craven | 9789024594917 | Boeken | bol
Rainfall Map Oklahoma
Walmart End Table Lamps
Condogames Xyz Discord
Aldi Sign In Careers
Closest Bj Near Me
Empire Visionworks The Crossings Clifton Park Photos
Www.patientnotebook/Atic
Craigslistodessa
Teekay Vop
Churchill Downs Racing Entries
Keshi with Mac Ayres and Starfall (Rescheduled from 11/1/2024) (POSTPONED) Tickets Thu, Nov 1, 2029 8:00 pm at Pechanga Arena - San Diego in San Diego, CA
Www Mydocbill Rada
Askhistorians Book List
Evil Dead Rise Showtimes Near Regal Sawgrass & Imax
Publix Coral Way And 147
Royal Caribbean Luggage Tags Pending
Smartfind Express Henrico
Craigslist In Myrtle Beach
Tyler Sis 360 Boonville Mo
Kips Sunshine Kwik Lube
Eleceed Mangaowl
Sc Pick 4 Evening Archives
Levothyroxine Ati Template
Fifty Shades Of Gray 123Movies
Nsav Investorshub
Directions To The Closest Auto Parts Store
Home Auctions - Real Estate Auctions
ESA Science & Technology - The remarkable Red Rectangle: A stairway to heaven? [heic0408]
Ladyva Is She Married
Payrollservers.us Webclock
Rs3 Nature Spirit Quick Guide
Garland County Mugshots Today
Catchvideo Chrome Extension
Port Huron Newspaper
Gt500 Forums
Mega Millions Lottery - Winning Numbers & Results
Plasma Donation Greensburg Pa
Concentrix + Webhelp devient Concentrix
Mike De Beer Twitter
Latest Posts
Article information

Author: Aron Pacocha

Last Updated:

Views: 5655

Rating: 4.8 / 5 (48 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Aron Pacocha

Birthday: 1999-08-12

Address: 3808 Moen Corner, Gorczanyport, FL 67364-2074

Phone: +393457723392

Job: Retail Consultant

Hobby: Jewelry making, Cooking, Gaming, Reading, Juggling, Cabaret, Origami

Introduction: My name is Aron Pacocha, I am a happy, tasty, innocent, proud, talented, courageous, magnificent person who loves writing and wants to share my knowledge and understanding with you.