Forecasting Metrics (GNU Octave (version 11.1.0))

### 26.4 Forecasting Metrics ¶

Octave supports the following functions for calculating forecasting metrics.

`E =` mape `(F, A)` ¶
`E =` mape `(F, A, dim)` ¶
`E =` mape `(F, A, vecdim)` ¶
`E =` mape `(F, A, "all")` ¶
`E =` mape `(…, nanflag)` ¶
`E =` mape `(…, zeroflag)` ¶
`E =` mape `(…, `'Weights'`, W)` ¶

  Compute the mean absolute percentage error between arrays.

  The mean absolute percentage error is defined as

      mape (F, A) = SUM_i (abs ((A(i) - F(i)) / A(i))) * 100 / N

  where N is the number of elements in F and A after broadcasting is applied to the subtraction operation.

  The weighted mean absolute percentage error is defined as

      weighted_mape (F, A) = SUM_i (W(i) * (abs ((A(i) - F(i)) / A(i)))) * 100 / SUM_i (W(i)

  where N is the number of elements in F and A after broadcasting is applied to the subtraction operation.

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

  If F and A are vectors of the same size, then `mape (F, A)` returns a scalar with the MAPE between the elements of F and A.

  If `A - F` is a matrix, then `mape (F, A)` returns a row vector with each element containing the MAPE between the corresponding columns of `A - F`.

  If `A - F` is an array, then `mape (F, A)` computes the MAPE along the first non-singleton dimension of the difference between the input arrays F and A. The size of E along the operating dimension is 1, while all other dimensions are the same as in `A - F`.

  The optional input dim specifies the dimension to operate on and must be a positive integer. Specifying any singleton dimension, including any dimension exceeding `ndims (A - F)`, will return `abs ((A - F) ./ A)`.

  Specifying the dimensions as vecdim, a vector of non-repeating dimensions, will return the mape over the array slice defined by vecdim. If vecdim indexes all dimensions in `A - F`, then it is equivalent to the option `"all"`. Any dimension in vecdim greater than `ndims (A - F)` is ignored.

  Specifying the dimension as `"all"` will cause `mape` to operate on all elements of `A - F`, and is equivalent to `mape ((A - F)(:))`.

  The optional variable nanflag specifies whether to include or exclude NaN values from the calculation using any of the previously specified input argument combinations. The default value for nanflag is `"includenan"` which keeps NaN values in the calculation. To exclude NaN values set the value of nanflag to `"omitnan"`. The output will still contain NaN values if `A - F` consists of all NaN values in the operating dimension.

  The optional variable zeroflag specifies whether to include or omit zero values from the calculation using any of the previously specified input argument combinations. The default value for zeroflag is `"includezero"`, in which case the calculated MAPE is Inf, if A contains one or more zeros. To ignore any zero values in A, set the value of zeroflag to `"omitzero"`. If A consists of all zero values in the operating dimension, then MAPE is NaN.

  The optional paired argument `…, "Weights", W` specifies a weighting scheme W, which is applied on the difference of the input arrays F and A, so that `mape` computes the weighted MAPE. When operating along a single dimension, W must be a vector of the same length as the operating dimension or it must have the same size as x. When operating over an array slice defined by vecdim, W must have the same size as the operating array slice, i.e. `size (A - F)(vecdim)`, or the same size as `A - F`.

  See also: rmse, mean, abs.

`E =` rmse `(F, A)` ¶
`E =` rmse `(F, A, dim)` ¶
`E =` rmse `(F, A, vecdim)` ¶
`E =` rmse `(F, A, "all")` ¶
`E =` rmse `(…, nanflag)` ¶
`E =` rmse `(…, `'Weights'`, W)` ¶

  Compute the root mean squared error between arrays.

  The root mean squared error is defined as

      rmse (F, A) = sqrt (SUM_i ((A(i) - F(i)) ^ 2) / N)

  where N is the number of elements in F and A after broadcasting is applied to the subtraction operation.

  The weighted root mean squared error is defined as

      weighted_rmse (F, A) = sqrt (SUM_i (W(i) * ((A(i) - F(i)) ^ 2)) / SUM_i (W(i)))

  where N is the number of elements in F and A after broadcasting is applied to the subtraction operation.

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

  If F and A are vectors of the same size, then `rmse (F, A)` returns a scalar with the RMSE between the elements of F and A.

  If `A - F` is a matrix, then `rmse (F, A)` returns a row vector with each element containing the RMSE between the corresponding columns of `A - F`.

  If `A - F` is an array, then `rmse (F, A)` computes the RMSE along the first non-singleton dimension of the difference between the input arrays F and A. The size of E along the operating dimension is 1, while all other dimensions are the same as in `A - F`.

  The optional input dim specifies the dimension to operate on and must be a positive integer. Specifying any singleton dimension, including any dimension exceeding `ndims (A - F)`, will return `abs ((A - F) ./ A)`.

  Specifying the dimensions as vecdim, a vector of non-repeating dimensions, will return the rmse over the array slice defined by vecdim. If vecdim indexes all dimensions in `A - F`, then it is equivalent to the option `"all"`. Any dimension in vecdim greater than `ndims (A - F)` is ignored.

  Specifying the dimension as `"all"` will cause `rmse` to operate on all elements of `A - F`, and is equivalent to `rmse ((A - F)(:))`.

  The optional variable nanflag specifies whether to include or exclude NaN values from the calculation using any of the previously specified input argument combinations. The default value for nanflag is `"includenan"` which keeps NaN values in the calculation. To exclude NaN values set the value of nanflag to `"omitnan"`. The output will still contain NaN values if `A - F` consists of all NaN values in the operating dimension.

  The optional paired argument `…, "Weights", W` specifies a weighting scheme W, which is applied on the difference of the input arrays F and A, so that `rmse` computes the weighted RMSE. When operating along a single dimension, W must be a vector of the same length as the operating dimension or it must have the same size as x. When operating over an array slice defined by vecdim, W must have the same size as the operating array slice, i.e. `size (A - F)(vecdim)`, or the same size as `A - F`.

  See also: mape, meansq, rms.