From 461b3bd850367f6c6de1dd638640071699b5c402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=C3=B4nio=20C=C3=A2ndido=20de=20Lima=20e=20Silva?= Date: Tue, 11 Jun 2019 13:07:27 -0300 Subject: [PATCH] Improvement on Box-Ljung text in Residual Analysis --- pyFTS/benchmarks/ResidualAnalysis.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pyFTS/benchmarks/ResidualAnalysis.py b/pyFTS/benchmarks/ResidualAnalysis.py index fbfa16a..ec42334 100644 --- a/pyFTS/benchmarks/ResidualAnalysis.py +++ b/pyFTS/benchmarks/ResidualAnalysis.py @@ -29,7 +29,7 @@ def chi_squared(q, h): return p -def compare_residuals(data, models): +def compare_residuals(data, models, alpha=.05): """ Compare residual's statistics of several models @@ -39,15 +39,16 @@ def compare_residuals(data, models): """ from statsmodels.stats.diagnostic import acorr_ljungbox rows = [] - columns = ["Model","Order","AVG","STD","Box-Ljung","p-value"] + columns = ["Model","Order","AVG","STD","Box-Ljung","p-value","Result"] for mfts in models: - forecasts = mfts.forecast(data) - res = residuals(data, forecasts, mfts.order) + forecasts = mfts.predict(data) + res = residuals(data, forecasts, mfts.order+1) mu = np.mean(res) sig = np.std(res) row = [mfts.shortname, mfts.order, mu, sig] stat, pval = acorr_ljungbox(res) - row.extend([stat, pval]) + test = 'H0 Accepted' if pval > alpha else 'H0 Rejected' + row.extend([stat, pval, test]) rows.append(row) return pd.DataFrame(rows, columns=columns)