Spaces:
Running
Running
Circhastic
commited on
Commit
•
128493f
1
Parent(s):
329b9f4
Version 1 hotfix #26 for merge
Browse files
app.py
CHANGED
@@ -176,7 +176,6 @@ def sales_growth(dataframe, fittedValues):
|
|
176 |
sales_growth['Forecasted Sales First Difference'].iloc[0] = (dataframe['Sales'].iloc[-1]-dataframe['Sales'].iloc[-2]).round(2)
|
177 |
sales_growth['Forecasted Sales Growth'].iloc[0]=(((dataframe['Sales'].iloc[-1]-dataframe['Sales'].iloc[-2])/dataframe['Sales'].iloc[-1])*100).round(2)
|
178 |
|
179 |
-
|
180 |
return sales_growth
|
181 |
|
182 |
@st.cache_data
|
@@ -196,24 +195,16 @@ def merge_forecast_data(actual, predicted, future):
|
|
196 |
return merged_dataframe
|
197 |
|
198 |
@st.cache_data
|
199 |
-
def
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
actual_date = actual['Date'].to_frame()
|
210 |
-
predicted_date = predicted['Date'].to_frame()
|
211 |
-
future_date = future['Date'].to_frame()
|
212 |
-
|
213 |
-
combined_date = pd.concat([actual_date, predicted_date, future_date])
|
214 |
-
combined_date = combined_date.reset_index()
|
215 |
-
combined_date = combined_date.drop(columns='index')
|
216 |
-
return combined_date
|
217 |
|
218 |
# TAPAS Model
|
219 |
|
@@ -366,10 +357,10 @@ if (st.session_state.uploaded):
|
|
366 |
|
367 |
test_y, predictions = np.array(test_y), np.array(fitted)
|
368 |
acc = forecast_accuracy(predictions, test_y)
|
|
|
369 |
|
370 |
col = st.columns(2)
|
371 |
with col[0]:
|
372 |
-
col[0].header("Sales Forecast")
|
373 |
merged_data = merge_forecast_data(df['Sales'], fitted_series, future_fitted_series)
|
374 |
|
375 |
fig = go.Figure()
|
@@ -377,8 +368,9 @@ if (st.session_state.uploaded):
|
|
377 |
fig.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Predicted Sales'], mode='lines', name='Predicted Sales'))
|
378 |
fig.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Forecasted Future Sales'], mode='lines', name='Forecasted Future Sales'))
|
379 |
fig.update_layout(title='Forecasted Sales Data', xaxis_title='Date', yaxis_title='Sales')
|
|
|
380 |
col[0].plotly_chart(fig)
|
381 |
-
col[0].write(f"MAPE score: {acc['mape']}
|
382 |
with col[1]:
|
383 |
col[1].subheader(f"Forecasted sales in the next {period} days")
|
384 |
col[1].write(df)
|
|
|
176 |
sales_growth['Forecasted Sales First Difference'].iloc[0] = (dataframe['Sales'].iloc[-1]-dataframe['Sales'].iloc[-2]).round(2)
|
177 |
sales_growth['Forecasted Sales Growth'].iloc[0]=(((dataframe['Sales'].iloc[-1]-dataframe['Sales'].iloc[-2])/dataframe['Sales'].iloc[-1])*100).round(2)
|
178 |
|
|
|
179 |
return sales_growth
|
180 |
|
181 |
@st.cache_data
|
|
|
195 |
return merged_dataframe
|
196 |
|
197 |
@st.cache_data
|
198 |
+
def interpret_mape(acc):
|
199 |
+
acc = acc * 100
|
200 |
+
if acc['mape'] < 10:
|
201 |
+
return "Great"
|
202 |
+
elif acc['mape'] < 20:
|
203 |
+
return "Good"
|
204 |
+
elif acc['mape'] < 50:
|
205 |
+
return "Relatively Good"
|
206 |
+
else:
|
207 |
+
return "Poor"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
# TAPAS Model
|
210 |
|
|
|
357 |
|
358 |
test_y, predictions = np.array(test_y), np.array(fitted)
|
359 |
acc = forecast_accuracy(predictions, test_y)
|
360 |
+
interpretation = interpret_mape(acc)
|
361 |
|
362 |
col = st.columns(2)
|
363 |
with col[0]:
|
|
|
364 |
merged_data = merge_forecast_data(df['Sales'], fitted_series, future_fitted_series)
|
365 |
|
366 |
fig = go.Figure()
|
|
|
368 |
fig.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Predicted Sales'], mode='lines', name='Predicted Sales'))
|
369 |
fig.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Forecasted Future Sales'], mode='lines', name='Forecasted Future Sales'))
|
370 |
fig.update_layout(title='Forecasted Sales Data', xaxis_title='Date', yaxis_title='Sales')
|
371 |
+
fig.update_xaxes(range=['2018-01-01', '2026-01-01'])
|
372 |
col[0].plotly_chart(fig)
|
373 |
+
col[0].write(f"MAPE score: {acc['mape'] * 100}% - {interpretation}")
|
374 |
with col[1]:
|
375 |
col[1].subheader(f"Forecasted sales in the next {period} days")
|
376 |
col[1].write(df)
|