Commit 16eedf99 authored by Boxiang Sun's avatar Boxiang Sun Committed by Thomas Gambier

check_free_disk_space: adapt to statsmodels 0.14.4

Refactor ARIMA calls and correctly specify the minimum version in
setup.py
parent afc3c08b
......@@ -11,7 +11,7 @@ for f in sorted(glob.glob(os.path.join('slapos', 'README.*.rst'))):
long_description += open("CHANGES.txt").read() + "\n"
prediction_require = ['statsmodels', 'scipy', 'pandas']
prediction_require = ['statsmodels>=0.14.0', 'scipy', 'pandas']
test_require = ['mock', 'cryptography', 'websockets; python_version>="3"',] + prediction_require
setup(name=name,
......
......@@ -22,7 +22,7 @@ from contextlib import closing
try:
import pandas as pd
import numpy as np
from statsmodels.tsa.arima_model import ARIMA
from statsmodels.tsa.arima.model import ARIMA
except ImportError:
pass
......@@ -127,8 +127,8 @@ class RunPromise(GenericPromise):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
model = ARIMA(history, order=arima_order)
model_fit = model.fit(disp=-1)
yhat = model_fit.forecast()[0]
model_fit = model.fit()
yhat = model_fit.get_forecast().predicted_mean[0]
predictions.append(yhat)
history.append(test[t])
# calculate out of sample error
......@@ -145,12 +145,12 @@ class RunPromise(GenericPromise):
for d in d_values:
for q in q_values:
order = (p,d,q)
try:
rmse = self.evaluateArimaModel(dataset, order)
if rmse < best_score:
best_score, best_cfg = rmse, order
except Exception:
pass
if rmse == 0.0:
self.logger.info("Found perfect model with order %s", order)
return best_cfg
return best_cfg
def diskSpacePrediction(self, disk_partition, database, date, time, day_range):
......@@ -191,11 +191,13 @@ class RunPromise(GenericPromise):
# disabling warnings during the ARIMA calculation
with warnings.catch_warnings():
warnings.simplefilter("ignore")
model_arima = ARIMA(df, order=best_cfg)
# disp < 0 means no output about convergence information
model_arima_fit = model_arima.fit(disp=-1)
model_arima = ARIMA(df, order=best_cfg, trend="t")
model_arima_fit = model_arima.fit()
# save ARIMA predictions
fcast, _, conf = model_arima_fit.forecast(max_date_predicted, alpha=0.05)
fcast_result = model_arima_fit.get_forecast(steps=max_date_predicted)
fcast = fcast_result.predicted_mean
conf = fcast_result.conf_int(alpha=0.05).to_numpy()
# pass the same index as the others
fcast = pd.Series(fcast, index=future_index_date)
if fcast.empty:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment