Socialify

Folder ..

Viewing model_builder.py
27 lines (23 loc) • 996.0 B

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pandas as pd
from functions.sql_functions import execute_sql_statement
import pmdarima as pm
import pickle

sql_stmt = "select date, city_id, cast(avg_temperature as real) as temp from temperature where date is not null and temp is not null"

result = execute_sql_statement(sql_stmt)
data = pd.DataFrame(result, columns=["date", "city_id", "temp"])
data.set_index(["date", "city_id"], inplace=True)
ts_model = pm.auto_arima(data.temp, start_p=1, start_q=1,
                         test='adf',
                         max_p=3, max_q=3,
                         m=5,
                         d=None,
                         seasonal=False,
                         start_P=0,
                         D=0,
                         trace=True,
                         error_action='ignore',
                         suppress_warnings=True,
                         stepwise=True)
# Best model:  ARIMA(3,0,3)(0,0,0)[0]

with open('arima.pkl', 'wb') as pkl:
    pickle.dump(ts_model, pkl)