Spaces:
Running
Running
Commit
·
255721c
1
Parent(s):
57d4b86
Update app showing graphs
Browse files- app.py +24 -18
- sample.csv +0 -0
app.py
CHANGED
|
@@ -315,9 +315,8 @@ if (st.session_state.uploaded):
|
|
| 315 |
train_test_model = test_fitting(df, training_X, training_y)
|
| 316 |
|
| 317 |
n_periods = round(len(df) * 0.2)
|
| 318 |
-
future_n_periods = forecast_period
|
| 319 |
fitted, confint = train_test_model.predict(X=test_X, n_periods=n_periods, return_conf_int=True)
|
| 320 |
-
index_of_fc = test_y_series.index
|
| 321 |
|
| 322 |
# make series for plotting purpose
|
| 323 |
fitted_series = pd.Series(fitted)
|
|
@@ -337,7 +336,6 @@ if (st.session_state.uploaded):
|
|
| 337 |
future_upper_series = pd.Series(confint[:, 1], index=future_index_of_fc)
|
| 338 |
|
| 339 |
future_sales_growth = sales_growth(df, future_fitted_series)
|
| 340 |
-
future_sales_growth = future_sales_growth.iloc[n_periods:]
|
| 341 |
df = dates_df(future_sales_growth)
|
| 342 |
|
| 343 |
test_y, predictions = np.array(test_y), np.array(fitted)
|
|
@@ -346,21 +344,29 @@ if (st.session_state.uploaded):
|
|
| 346 |
|
| 347 |
merged_data = merge_forecast_data(df['Sales'], fitted_series, future_fitted_series)
|
| 348 |
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
with st.form("question_form"):
|
| 365 |
question = st.text_input('Ask a Question about the Forecasted Data', placeholder="What is the total sales in the month of December?")
|
| 366 |
query_button = st.form_submit_button(label='Generate Answer')
|
|
|
|
| 315 |
train_test_model = test_fitting(df, training_X, training_y)
|
| 316 |
|
| 317 |
n_periods = round(len(df) * 0.2)
|
| 318 |
+
future_n_periods = forecast_period
|
| 319 |
fitted, confint = train_test_model.predict(X=test_X, n_periods=n_periods, return_conf_int=True)
|
|
|
|
| 320 |
|
| 321 |
# make series for plotting purpose
|
| 322 |
fitted_series = pd.Series(fitted)
|
|
|
|
| 336 |
future_upper_series = pd.Series(confint[:, 1], index=future_index_of_fc)
|
| 337 |
|
| 338 |
future_sales_growth = sales_growth(df, future_fitted_series)
|
|
|
|
| 339 |
df = dates_df(future_sales_growth)
|
| 340 |
|
| 341 |
test_y, predictions = np.array(test_y), np.array(fitted)
|
|
|
|
| 344 |
|
| 345 |
merged_data = merge_forecast_data(df['Sales'], fitted_series, future_fitted_series)
|
| 346 |
|
| 347 |
+
|
| 348 |
+
col_charts = st.columns(2)
|
| 349 |
+
with col_charts[0]:
|
| 350 |
+
fig_compare = go.Figure()
|
| 351 |
+
fig_compare.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Actual Sales'], mode='lines', name='Actual Sales'))
|
| 352 |
+
fig_compare.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Predicted Sales'], mode='lines', name='Predicted Sales'))
|
| 353 |
+
fig_compare.update_layout(title='Historical Sales Data', xaxis_title='Date', yaxis_title='Sales')
|
| 354 |
+
fig_compare.update_xaxes(range=['2020-01-01', '2025-01-01']) # TODO: Change this to be adaptive
|
| 355 |
+
st.plotly_chart(fig_compare, use_container_width=True)
|
| 356 |
+
with col_charts[1]:
|
| 357 |
+
fig_forecast = go.Figure()
|
| 358 |
+
fig_compare.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Forecasted Future Sales'], mode='lines', name='Forecasted Future Sales'))
|
| 359 |
+
fig_compare.update_layout(title='Forecasted Sales Data', xaxis_title='Date', yaxis_title='Sales')
|
| 360 |
+
# fig_compare.update_xaxes(range=['2020-01-01', '2025-01-01']) # TODO: Change this to be adaptive
|
| 361 |
+
st.plotly_chart(fig_compare, use_container_width=True)
|
| 362 |
+
st.write(f"MAPE score: {mape}% - {interpretation}")
|
| 363 |
+
|
| 364 |
+
col_table = st.columns(2)
|
| 365 |
+
with col_table[0]:
|
| 366 |
+
col_table[0].subheader(f"Forecasted sales in the next {period} days")
|
| 367 |
+
col_table[0].write(df)
|
| 368 |
+
with col_table[1]:
|
| 369 |
+
col_table[1] = st.subheader("Question-Answering")
|
| 370 |
with st.form("question_form"):
|
| 371 |
question = st.text_input('Ask a Question about the Forecasted Data', placeholder="What is the total sales in the month of December?")
|
| 372 |
query_button = st.form_submit_button(label='Generate Answer')
|
sample.csv
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|