aboutsummaryrefslogtreecommitdiff
path: root/model_builder.py
diff options
context:
space:
mode:
Diffstat (limited to 'model_builder.py')
-rw-r--r--model_builder.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/model_builder.py b/model_builder.py
new file mode 100644
index 0000000..b12897a
--- /dev/null
+++ b/model_builder.py
@@ -0,0 +1,27 @@
+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)
+