Update app.py
Browse files
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 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
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 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
st.line_chart(forecast)
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
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 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|