XPMaster commited on
Commit
89e8e44
1 Parent(s): 939b379

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -16
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
- # Grid search button
77
- if st.button(f'Run Grid Search for {city}'):
78
- best_aic = float('inf')
79
- best_params = None
80
- for param_set in product(range(3), repeat=3): # Adjust the range and repeat parameters as needed
81
- for seasonal_param_set in product(range(3), repeat=4): # Adjust for seasonal parameters
82
- _, temp_aic = run_sarimax(city_data, param_set, seasonal_param_set+(12,))
83
- if temp_aic and temp_aic < best_aic:
84
- best_aic = temp_aic
85
- best_params = (param_set, seasonal_param_set+(12,))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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'):