Spaces:
Running
Running
Circhastic
commited on
Commit
•
8b45a7a
1
Parent(s):
a6370b3
Fix app
Browse files
app.py
CHANGED
@@ -133,19 +133,19 @@ def train_test(dataframe):
|
|
133 |
future_X = dataframe.iloc[0:,1:]
|
134 |
return (training_y, test_y, test_y_series, training_X, test_X, future_X)
|
135 |
|
136 |
-
@st.cache_data
|
137 |
-
def model_fitting(dataframe, Exo):
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
|
150 |
@st.cache_data
|
151 |
def test_fitting(dataframe, Exo, trainY):
|
@@ -242,8 +242,8 @@ st.subheader("Welcome User, start using the application by uploading your file i
|
|
242 |
if 'uploaded' not in st.session_state:
|
243 |
st.session_state.uploaded = False
|
244 |
|
245 |
-
|
246 |
-
|
247 |
|
248 |
# Sidebar Menu
|
249 |
with st.sidebar:
|
@@ -271,7 +271,7 @@ with st.sidebar:
|
|
271 |
st.download_button("Download our sample CSV", f, file_name='sample.csv')
|
272 |
|
273 |
if (st.session_state.uploaded):
|
274 |
-
st.line_chart(series)
|
275 |
|
276 |
MIN_DAYS = 30
|
277 |
MAX_DAYS = 90
|
@@ -284,7 +284,7 @@ if (st.session_state.uploaded):
|
|
284 |
type="primary",
|
285 |
)
|
286 |
|
287 |
-
if (forecast_button):
|
288 |
df = series_to_df_exogenous(series)
|
289 |
|
290 |
train = train_test(df)
|
@@ -292,6 +292,7 @@ if (st.session_state.uploaded):
|
|
292 |
train_test_model = test_fitting(df, training_X, training_y)
|
293 |
|
294 |
n_periods = round(len(df) * 0.2)
|
|
|
295 |
future_n_periods = forecast_period + n_periods
|
296 |
|
297 |
fitted, confint = train_test_model.predict(X=test_X, n_periods=n_periods, return_conf_int=True)
|
@@ -316,10 +317,11 @@ if (st.session_state.uploaded):
|
|
316 |
future_upper_series = pd.Series(confint[:, 1], index=future_index_of_fc)
|
317 |
|
318 |
future_sales_growth = sales_growth(df, future_fitted_series)
|
319 |
-
|
320 |
df = dates_df(future_sales_growth)
|
321 |
st.write("Forecasted sales in the next 3 months")
|
322 |
st.write(df)
|
|
|
323 |
|
324 |
with st.form("question_form"):
|
325 |
question = st.text_input('Ask a Question about the Forecasted Data', placeholder="What is the total sales in the month of December?")
|
|
|
133 |
future_X = dataframe.iloc[0:,1:]
|
134 |
return (training_y, test_y, test_y_series, training_X, test_X, future_X)
|
135 |
|
136 |
+
# @st.cache_data
|
137 |
+
# def model_fitting(dataframe, Exo):
|
138 |
+
# futureModel = pm.auto_arima(dataframe['Sales'], X=Exo, start_p=1, start_q=1,
|
139 |
+
# test='adf',min_p=1,min_q=1,
|
140 |
+
# max_p=3, max_q=3, m=12,
|
141 |
+
# start_P=0, seasonal=True,
|
142 |
+
# d=None, D=1, trace=True,
|
143 |
+
# error_action='ignore',
|
144 |
+
# suppress_warnings=True,
|
145 |
+
# stepwise=True,
|
146 |
+
# maxiter=5)
|
147 |
+
# model = futureModel
|
148 |
+
# return model
|
149 |
|
150 |
@st.cache_data
|
151 |
def test_fitting(dataframe, Exo, trainY):
|
|
|
242 |
if 'uploaded' not in st.session_state:
|
243 |
st.session_state.uploaded = False
|
244 |
|
245 |
+
if 'forecasted' not in st.session_state:
|
246 |
+
st.session_state.forecasted = False
|
247 |
|
248 |
# Sidebar Menu
|
249 |
with st.sidebar:
|
|
|
271 |
st.download_button("Download our sample CSV", f, file_name='sample.csv')
|
272 |
|
273 |
if (st.session_state.uploaded):
|
274 |
+
st.line_chart(series)
|
275 |
|
276 |
MIN_DAYS = 30
|
277 |
MAX_DAYS = 90
|
|
|
284 |
type="primary",
|
285 |
)
|
286 |
|
287 |
+
if (forecast_button or st.session_state.forecasted):
|
288 |
df = series_to_df_exogenous(series)
|
289 |
|
290 |
train = train_test(df)
|
|
|
292 |
train_test_model = test_fitting(df, training_X, training_y)
|
293 |
|
294 |
n_periods = round(len(df) * 0.2)
|
295 |
+
|
296 |
future_n_periods = forecast_period + n_periods
|
297 |
|
298 |
fitted, confint = train_test_model.predict(X=test_X, n_periods=n_periods, return_conf_int=True)
|
|
|
317 |
future_upper_series = pd.Series(confint[:, 1], index=future_index_of_fc)
|
318 |
|
319 |
future_sales_growth = sales_growth(df, future_fitted_series)
|
320 |
+
future_sales_growth = future_sales_growth.iloc[n_periods:]
|
321 |
df = dates_df(future_sales_growth)
|
322 |
st.write("Forecasted sales in the next 3 months")
|
323 |
st.write(df)
|
324 |
+
st.session_state.forecasted = True
|
325 |
|
326 |
with st.form("question_form"):
|
327 |
question = st.text_input('Ask a Question about the Forecasted Data', placeholder="What is the total sales in the month of December?")
|