Commit ee2afd05 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

support for statsmodels 14.4

See merge request !141
parents cc665e37 16eedf99
......@@ -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
rmse = self.evaluateArimaModel(dataset, order)
if rmse < best_score:
best_score, best_cfg = rmse, order
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:
......
......@@ -223,10 +223,9 @@ class CheckUrlAvailableMixin(TestPromisePluginMixin):
server = BaseHTTPServer.HTTPServer(
(SLAPOS_TEST_IPV4, SLAPOS_TEST_IPV4_PORT),
cls.RequestHandler)
server.socket = ssl.wrap_socket(
server.socket,
certfile=cls.test_server_certificate_file.name,
server_side=True)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(certfile=cls.test_server_certificate_file.name)
server.socket = context.wrap_socket(server.socket, server_side=True)
server.serve_forever()
cls.server_process = multiprocessing.Process(target=server)
......
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