You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calculating the SMAPE metric in the diagnostics.performance_metrics() function, there is the possibility for a zero division if y and yhat are both zero.
defsmape(df, w):
"""Symmetric mean absolute percentage error based on Chen and Yang (2004) formula Parameters ---------- df: Cross-validation results dataframe. w: Aggregation window size. Returns ------- Dataframe with columns horizon and smape. """sape=np.abs(df['y'] -df['yhat']) / ((np.abs(df['y']) +np.abs(df['yhat'])) /2) <----POSSIBLEZERODIVISIONifw<0:
returnpd.DataFrame({'horizon': df['horizon'], 'smape': sape})
returnrolling_mean_by_h(
x=sape.values, h=df['horizon'].values, w=w, name='smape'
)
This does not cause an error directly, however, it results in np.nan values where zero division occurs. When the rolling_mean_by_h() function is called, there is a groupby() which removes any np.nan values. This becomes an issue in the main performance_metrics() function with the following assert:
This is part of a loop that checks each of the metrics ensuring that they are the same length and fails given the above scenario, as np.nan values are removed and that metric returns fewer values.
Issue
When calculating the SMAPE metric in the
diagnostics.performance_metrics()
function, there is the possibility for a zero division ify
andyhat
are both zero.This does not cause an error directly, however, it results in
np.nan
values where zero division occurs. When therolling_mean_by_h()
function is called, there is agroupby()
which removes anynp.nan
values. This becomes an issue in the mainperformance_metrics()
function with the following assert:This is part of a loop that checks each of the metrics ensuring that they are the same length and fails given the above scenario, as
np.nan
values are removed and that metric returns fewer values.Replication
Here is how you can replicate this issue:
We set certain values in the training data to zero and clip negative values to create a scenario where
y
andyhat
are both zero.The text was updated successfully, but these errors were encountered: