2.7 C
London
Thursday, November 28, 2024
HomeStatistics TutorialStatologyHow to Calculate SMAPE in Python

How to Calculate SMAPE in Python

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories