mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-11-18 08:53:42 +00:00
Fix Issue #2577 - Zero Division Error in diagnostics.performance_metrics() causing failed assertion (#2578)
This commit is contained in:
parent
7dfedae3f8
commit
36421b70f0
2 changed files with 8 additions and 0 deletions
|
|
@ -630,6 +630,7 @@ def smape(df, w):
|
||||||
Dataframe with columns horizon and smape.
|
Dataframe with columns horizon and smape.
|
||||||
"""
|
"""
|
||||||
sape = np.abs(df['y'] - df['yhat']) / ((np.abs(df['y']) + np.abs(df['yhat'])) / 2)
|
sape = np.abs(df['y'] - df['yhat']) / ((np.abs(df['y']) + np.abs(df['yhat'])) / 2)
|
||||||
|
sape = sape.fillna(0)
|
||||||
if w < 0:
|
if w < 0:
|
||||||
return pd.DataFrame({'horizon': df['horizon'], 'smape': sape})
|
return pd.DataFrame({'horizon': df['horizon'], 'smape': sape})
|
||||||
return rolling_mean_by_h(
|
return rolling_mean_by_h(
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,13 @@ class TestPerformanceMetrics:
|
||||||
metrics=["coverage", "mape"],
|
metrics=["coverage", "mape"],
|
||||||
)
|
)
|
||||||
assert set(df_horizon.columns) == {"coverage", "horizon"}
|
assert set(df_horizon.columns) == {"coverage", "horizon"}
|
||||||
|
# Handle zero y and yhat
|
||||||
|
df_cv["y"] = 0.0
|
||||||
|
df_cv["yhat"] = 0.0
|
||||||
|
df_horizon = diagnostics.performance_metrics(
|
||||||
|
df_cv,
|
||||||
|
)
|
||||||
|
assert set(df_horizon.columns) == {"coverage", "horizon", "mae", "mdape", "mse", "rmse", "smape"}
|
||||||
df_horizon = diagnostics.performance_metrics(
|
df_horizon = diagnostics.performance_metrics(
|
||||||
df_cv,
|
df_cv,
|
||||||
metrics=["mape"],
|
metrics=["mape"],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue