Skip to content

[Machine Learning] Introduction To SMAPE Metric (With Example)

Last Updated on 2021-11-17 by Clay

Symmetric Mean Absolute Percentage Error (SMAPE) is a classic evaluation metric for "predicted value and actual value".

It can be regarded as a kind of improvement of Mean Absolute Percentage Error (MAPE), because MAPE does not predict the limit for the case where the predicted value is higher than the actual value, but it has the lower case, so it will be called symmetry.

This evaluation metric is mostly used for regression problems rather than classification problems.


SMAPE Formula

  • n is the total number of sequences
  • F_t is the predicted value
  • A_t is the actual value

Program implementation (Python)

The following programs use the numpy package.

# coding: utf-8
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)


def main():
    actual = np.array([12.3, 21.4, 14.0, 1.51, 14.6, 21.5, 83.1])
    forecast = np.array([11.5, 13.0, 14.3, 1.49, 15.3, 16.9, 81.2])

    print("{:.4}%".format(smape(actual, forecast)))


if __name__ == "__main__":
    main()


Output:

12.85%


(Supplement) PyTorch version

PyTorch is a very useful deep learning framework, so I will also add the PyTorch version here.

def smape(outputs, answers):
    return torch.mean(2*torch.abs(outputs-answers)/(torch.abs(answers)+torch.abs(outputs)))



References


Read More

Leave a Reply