Update app.py
Browse files
app.py
CHANGED
@@ -73,23 +73,35 @@ for tab, city in zip(tabs, unique_cities):
|
|
73 |
fig = px.line(forecast_df, x=forecast_df.index, y="Forecast")
|
74 |
st.plotly_chart(fig)
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
-
# Updating session state with the best parameters
|
88 |
-
st.session_state.best_params = {
|
89 |
-
'order': best_params[0],
|
90 |
-
'seasonal_order': best_params[1]
|
91 |
-
}
|
92 |
-
st.write(f"Best Parameters for {city}: {best_params} with AIC: {best_aic}")
|
93 |
|
94 |
# Export to Excel button
|
95 |
if st.button(f'Export {city} to Excel'):
|
|
|
73 |
fig = px.line(forecast_df, x=forecast_df.index, y="Forecast")
|
74 |
st.plotly_chart(fig)
|
75 |
|
76 |
+
# Grid search button
|
77 |
+
if st.button(f'Run Grid Search for {city}'):
|
78 |
+
best_aic = float('inf')
|
79 |
+
best_params = None
|
80 |
+
# Define the range for each parameter
|
81 |
+
p_range = d_range = q_range = range(3)
|
82 |
+
P_range = D_range = Q_range = range(3)
|
83 |
+
S = 12 # Assuming a fixed seasonal period, adjust as needed
|
84 |
+
|
85 |
+
# Perform the grid search
|
86 |
+
for params in product(p_range, d_range, q_range, P_range, D_range, Q_range):
|
87 |
+
order = params[:3]
|
88 |
+
seasonal_order = params[3:] + (S,)
|
89 |
+
try:
|
90 |
+
_, temp_aic = run_sarimax(city_data, order, seasonal_order)
|
91 |
+
if temp_aic < best_aic:
|
92 |
+
best_aic = temp_aic
|
93 |
+
best_params = (order, seasonal_order)
|
94 |
+
except Exception as e:
|
95 |
+
st.error(f"An error occurred for parameters {params}: {e}")
|
96 |
+
|
97 |
+
# Update the session state with the best parameters
|
98 |
+
if best_params is not None:
|
99 |
+
st.session_state.best_params = {
|
100 |
+
'order': best_params[0],
|
101 |
+
'seasonal_order': best_params[1]
|
102 |
+
}
|
103 |
+
st.write(f"Best Parameters for {city}: {best_params} with AIC: {best_aic}")
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
# Export to Excel button
|
107 |
if st.button(f'Export {city} to Excel'):
|