Circhastic commited on
Commit
9441b2b
1 Parent(s): cb240bf

Version 1 hotfix #16 for merge

Browse files
Files changed (1) hide show
  1. app.py +31 -8
app.py CHANGED
@@ -194,9 +194,29 @@ def merge_forecast_data(actual, predicted, future):
194
  # merged_dataframe = pd.merge_ordered(actual, predicted, on='Date', suffixes=('_Actual', '_Predicted'))
195
  # merged_dataframe = pd.merge_ordered(merged_dataframe, future, on='Date')
196
  merged_dataframe = pd.concat([actual, predicted, future], axis=1)
197
- merged_dataframe = merged_dataframe.set_index('Date')
198
  return merged_dataframe
199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  # TAPAS Model
201
 
202
  @st.cache_resource
@@ -348,16 +368,19 @@ if (st.session_state.uploaded):
348
 
349
  test_y, predictions = np.array(test_y), np.array(fitted)
350
  acc = forecast_accuracy(predictions, test_y)
351
-
352
  col = st.columns(2)
353
  with col[0]:
354
- col[0].header("Sales Forecast")
355
- merged_data = merge_forecast_data(df['Sales'], fitted_series, future_fitted_series)
356
- col[0].line_chart(merged_data)
357
- col[0].write(f"MAPE score: {acc['mape']} (lower is better)")
 
 
 
358
  with col[1]:
359
- col[1].subheader(f"Forecasted sales in the next {period} days")
360
- col[1].write(df)
361
  st.session_state.forecasted = True
362
 
363
 
 
194
  # merged_dataframe = pd.merge_ordered(actual, predicted, on='Date', suffixes=('_Actual', '_Predicted'))
195
  # merged_dataframe = pd.merge_ordered(merged_dataframe, future, on='Date')
196
  merged_dataframe = pd.concat([actual, predicted, future], axis=1)
197
+ # merged_dataframe = merged_dataframe.set_index('Date')
198
  return merged_dataframe
199
 
200
+ @st.cache_data
201
+ def get_combined_date(actual, predicted, future):
202
+ actual = actual.to_frame()
203
+ predicted = predicted.to_frame()
204
+ future = future.to_frame()
205
+ future = future.rename_axis('Date')
206
+
207
+ actual = actual.reset_index()
208
+ predicted = predicted.reset_index()
209
+ future = future.reset_index()
210
+
211
+ actual_date = actual['Date'].to_frame()
212
+ predicted_date = predicted['Date'].to_frame()
213
+ future_date = future['Date'].to_frame()
214
+
215
+ combined_date = pd.concat([actual_date, predicted_date, future_date])
216
+ combined_date = combined_date.reset_index()
217
+ combined_date = combined_date.drop(columns='index')
218
+ return combined_date
219
+
220
  # TAPAS Model
221
 
222
  @st.cache_resource
 
368
 
369
  test_y, predictions = np.array(test_y), np.array(fitted)
370
  acc = forecast_accuracy(predictions, test_y)
371
+
372
  col = st.columns(2)
373
  with col[0]:
374
+ col[0].header("Sales Forecast")
375
+ # merged_data = plot_data(df['Sales'], fitted_series, future_fitted_series)
376
+ # date = get_combined_date(df['Sales'], fitted_series, future_fitted_series)
377
+ # col[0].line_chart(x=date, y=[df['Sales'], fitted_series], color='blue', key='actual')
378
+ merged_data = merge_forecast_data(df['Sales'], fitted_series, future_fitted_series)
379
+ col[0].line_chart(merged_data, x="Date", y=["Actual Sales", "Predicted Sales", "Future Forecasted Sales"], key='actual')
380
+ col[0].write(f"MAPE score: {acc['mape']} (lower is better)")
381
  with col[1]:
382
+ col[1].subheader(f"Forecasted sales in the next {period} days")
383
+ col[1].write(df)
384
  st.session_state.forecasted = True
385
 
386