mean_squared_percentage_error(y_true, y_pred, horizon_weight=None, multioutput='uniform_average', square_root=False, symmetric=False, **kwargs)[source]#

Mean squared percentage error (MSPE) or square root version.

If square_root is False then calculates MSPE and if square_root is True then calculates root mean squared percentage error (RMSPE). If symmetric is True then calculates sMSPE or sRMSPE. Output is non-negative floating point. The best value is 0.0.

MSPE is measured in squared percentage error relative to the test data and RMSPE is measured in percentage error relative to the test data. Because the calculation takes the square rather than absolute value of the percentage forecast error, large errors are penalized more than MAPE, sMAPE, MdAPE or sMdAPE.

There is no limit on how large the error can be, particulalrly when y_true values are close to zero. In such cases the function returns a large value instead of inf.

y_truepd.Series, pd.DataFrame or np.array of shape (fh,) or (fh, n_outputs) where fh is the forecasting horizon

Ground truth (correct) target values.

y_predpd.Series, pd.DataFrame or np.array of shape (fh,) or (fh, n_outputs) where fh is the forecasting horizon

Forecasted values.

horizon_weightarray-like of shape (fh,), default=None

Forecast horizon weights.

multioutput{‘raw_values’, ‘uniform_average’} or array-like of shape (n_outputs,), default=’uniform_average’

Defines how to aggregate metric for multivariate (multioutput) data. If array-like, values used as weights to average the errors. If ‘raw_values’, returns a full set of errors in case of multioutput input. If ‘uniform_average’, errors of all outputs are averaged with uniform weight.

square_rootbool, default=False

Whether to take the square root of the mean squared error. If True, returns root mean squared error (RMSPE) If False, returns mean squared error (MSPE)

symmetricbool, default=False

Calculates symmetric version of metric if True.


MSPE or RMSPE loss. If multioutput is ‘raw_values’, then MSPE or RMSPE is returned for each output separately. If multioutput is ‘uniform_average’ or an ndarray of weights, then the weighted average MSPE or RMSPE of all output errors is returned.


Hyndman, R. J and Koehler, A. B. (2006). “Another look at measures of forecast accuracy”, International Journal of Forecasting, Volume 22, Issue 4.


>>> from sktime.performance_metrics.forecasting import mean_squared_percentage_error
>>> y_true = np.array([3, -0.5, 2, 7, 2])
>>> y_pred = np.array([2.5, 0.0, 2, 8, 1.25])
>>> mean_squared_percentage_error(y_true, y_pred, symmetric=False)
>>> mean_squared_percentage_error(y_true, y_pred, square_root=True,     symmetric=False)
>>> y_true = np.array([[0.5, 1], [-1, 1], [7, -6]])
>>> y_pred = np.array([[0, 2], [-1, 2], [8, -5]])
>>> mean_squared_percentage_error(y_true, y_pred, symmetric=False)
>>> mean_squared_percentage_error(y_true, y_pred, square_root=True,     symmetric=False)
>>> mean_squared_percentage_error(y_true, y_pred, multioutput='raw_values',     symmetric=False)
array([0.34013605, 0.67592593])
>>> mean_squared_percentage_error(y_true, y_pred, multioutput='raw_values',     square_root=True, symmetric=False)
array([0.58321184, 0.82214714])
>>> mean_squared_percentage_error(y_true, y_pred, multioutput=[0.3, 0.7],     symmetric=False)
>>> mean_squared_percentage_error(y_true, y_pred, multioutput=[0.3, 0.7],     square_root=True, symmetric=False)