XPMaster commited on
Commit
37f0b43
β€’
1 Parent(s): 445e5e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -32
app.py CHANGED
@@ -36,42 +36,43 @@ def to_excel(df):
36
 
37
  st.title("Exponential Smoothing Forecasting")
38
  # Upload Data Section
39
- uploaded_file = st.file_uploader("Choose a file")
40
- if uploaded_file is not None:
41
- data = create_data()
42
- unique_cities = data['City'].unique()
43
 
44
- # Select a city
45
- selected_city = st.selectbox('Select a City', unique_cities)
46
 
47
- # Sliders for parameter adjustment
48
- trend = st.select_slider('Select Trend', options=['add', 'mul', None])
49
- damped_trend = st.checkbox('Damped Trend')
50
- seasonal = st.select_slider('Select Seasonal', options=['add', 'mul', None])
51
- seasonal_period = st.slider('Seasonal Period', 1, 24, 12)
52
 
53
- # Display forecast with current parameters
54
- city_data = data[data['City'] == selected_city]['Accident Count']
55
- forecast, aic = run_exp_smoothing(city_data, trend, damped_trend, seasonal, seasonal_period)
56
- if forecast is not None:
57
- st.write(f"Forecast with AIC: {aic}")
58
- st.line_chart(forecast)
59
 
60
- # Grid search button
61
- if st.button('Run Grid Search'):
62
- best_aic = float('inf')
63
- best_params = None
64
- for param_set in product(['add', 'mul', None], [True, False], ['add', 'mul', None], [12]):
65
- _, temp_aic = run_exp_smoothing(city_data, *param_set)
66
- if temp_aic and temp_aic < best_aic:
67
- best_aic = temp_aic
68
- best_params = param_set
69
- st.write(f"Best Parameters: {best_params} with AIC: {best_aic}")
70
 
71
- # Export to Excel button
72
- # if st.button('Export to Excel'):
73
- # df_to_export = pd.DataFrame(forecast)
74
- # excel_data = to_excel(df_to_export)
75
- # st.download_button(label='πŸ“₯ Download Excel', data=excel_data, file_name='forecast.xlsx', mime='application/vnd.ms-excel')
 
 
 
 
 
 
 
 
 
 
 
76
 
77
 
 
36
 
37
  st.title("Exponential Smoothing Forecasting")
38
  # Upload Data Section
39
+ # uploaded_file = st.file_uploader("Choose a file")
40
+ # if uploaded_file is not None:
 
 
41
 
42
+ data = create_data()
43
+ unique_cities = data['City'].unique()
44
 
45
+ # Select a city
46
+ selected_city = st.selectbox('Select a City', unique_cities)
 
 
 
47
 
48
+ # Sliders for parameter adjustment
49
+ trend = st.select_slider('Select Trend', options=['add', 'mul', None])
50
+ damped_trend = st.checkbox('Damped Trend')
51
+ seasonal = st.select_slider('Select Seasonal', options=['add', 'mul', None])
52
+ seasonal_period = st.slider('Seasonal Period', 1, 24, 12)
 
53
 
54
+ # Display forecast with current parameters
55
+ city_data = data[data['City'] == selected_city]['Accident Count']
56
+ forecast, aic = run_exp_smoothing(city_data, trend, damped_trend, seasonal, seasonal_period)
57
+ if forecast is not None:
58
+ st.write(f"Forecast with AIC: {aic}")
59
+ st.line_chart(forecast)
 
 
 
 
60
 
61
+ # Grid search button
62
+ if st.button('Run Grid Search'):
63
+ best_aic = float('inf')
64
+ best_params = None
65
+ for param_set in product(['add', 'mul', None], [True, False], ['add', 'mul', None], [12]):
66
+ _, temp_aic = run_exp_smoothing(city_data, *param_set)
67
+ if temp_aic and temp_aic < best_aic:
68
+ best_aic = temp_aic
69
+ best_params = param_set
70
+ st.write(f"Best Parameters: {best_params} with AIC: {best_aic}")
71
+
72
+ # Export to Excel button
73
+ # if st.button('Export to Excel'):
74
+ # df_to_export = pd.DataFrame(forecast)
75
+ # excel_data = to_excel(df_to_export)
76
+ # st.download_button(label='πŸ“₯ Download Excel', data=excel_data, file_name='forecast.xlsx', mime='application/vnd.ms-excel')
77
 
78