*34*

The **symmetric mean absolute percentage error (SMAPE) **is used to measure the predictive accuracy of models. It is calculated as:

**SMAPE** = (1/n) * Σ(|forecast – actual| / ((|actual| + |forecast|)/2) * 100

where:

**Σ**– a symbol that means “sum”**n**– sample size**actual**– the actual data value**forecast**– the forecasted data value

This tutorial explains how to calculate SMAPE in Python.

**How to Calculate SMAPE in Python**

There is no built-in Python function to calculate SMAPE, but we can create a simple function to do so:

import numpy as np def smape(a, f): return 1/len(a) * np.sum(2 * np.abs(f-a) / (np.abs(a) + np.abs(f))*100)

We can then use this function to calculate the SMAPE for two arrays: one that contains the actual data values and one that contains the forecasted data values.

#define arrays of actual and forecasted data values actual = np.array([12, 13, 14, 15, 15,22, 27]) forecast = np.array([11, 13, 14, 14, 15, 16, 18]) #calculate SMAPE smape(actual, forecast) 12.45302

From the results we can see that the symmetric mean absolute percentage error for this model is **12.45302%**.

**Additional Resources**

Wikipedia Entry for SMAPE

Rob J. Hyndman’s thoughts on SMAPE

How to Calculate MAPE in Python

How to Calculate MAPE in R

How to Calculate MAPE in Excel