From d432ff4a9e41a8bb1b84ca43b08c6ef17cea5ccc Mon Sep 17 00:00:00 2001 From: jope35 Date: Fri, 2 Nov 2018 21:08:40 +0100 Subject: [PATCH] add symmetric mean absolute percentage error (#721) --- python/fbprophet/diagnostics.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/python/fbprophet/diagnostics.py b/python/fbprophet/diagnostics.py index 0ed20b8..7de2b26 100644 --- a/python/fbprophet/diagnostics.py +++ b/python/fbprophet/diagnostics.py @@ -325,6 +325,22 @@ def mape(df, w): return rolling_mean(ape.values, w) +def smape(df, w): + """Symmetric mean absolute percentage error + + Parameters + ---------- + df: Cross-validation results dataframe. + w: Aggregation window size. + + Returns + ------- + Array of symmetric mean absolute percent errors. + """ + sape = np.abs(df['yhat']-df['y']) / ((np.abs(df['y']) + np.abs(df['yhat'])) /2) + return rolling_mean(sape.values, w) + + def coverage(df, w): """Coverage