Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -164,7 +164,7 @@ def model_train(df,model, ds_col, freq):
|
|
164 |
nf.fit(df)
|
165 |
return model
|
166 |
|
167 |
-
def forecast_time_series(df, model_type, horizon, max_steps=200, ds_col='ds'):
|
168 |
start_time = time.time() # Start timing
|
169 |
freq = determine_frequency(df, ds_col)
|
170 |
st.sidebar.write(f"Data frequency: {freq}")
|
@@ -177,11 +177,11 @@ def forecast_time_series(df, model_type, horizon, max_steps=200, ds_col='ds'):
|
|
177 |
forecast_results[model_type] = generate_forecast(model, df, tag='retrain')
|
178 |
|
179 |
for model_name, forecast_df in forecast_results.items():
|
180 |
-
plot_forecasts(forecast_df, df, f'{model_name} Forecast
|
181 |
|
182 |
end_time = time.time() # End timing
|
183 |
time_taken = end_time - start_time
|
184 |
-
st.
|
185 |
|
186 |
@st.cache_data
|
187 |
def load_default():
|
@@ -218,6 +218,7 @@ def transfer_learning_forecasting():
|
|
218 |
|
219 |
df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
|
220 |
df['unique_id']=1
|
|
|
221 |
st.session_state.df = df
|
222 |
|
223 |
# Determine frequency of data
|
@@ -239,11 +240,11 @@ def transfer_learning_forecasting():
|
|
239 |
forecast_results['TFT'] = generate_forecast(tft_model, df)
|
240 |
|
241 |
for model_name, forecast_df in forecast_results.items():
|
242 |
-
plot_forecasts(forecast_df, df, f'{model_name} Forecast')
|
243 |
|
244 |
end_time = time.time() # End timing
|
245 |
time_taken = end_time - start_time
|
246 |
-
st.
|
247 |
|
248 |
def dynamic_forecasting():
|
249 |
st.title("Dynamic Forecasting")
|
@@ -263,7 +264,11 @@ def dynamic_forecasting():
|
|
263 |
y_col = st.selectbox("Select Target column", options=columns, index=columns.index('y') if 'y' in columns else 1)
|
264 |
# unique_id_col = st.text_input("Unique ID column (default: '1')", value="1")
|
265 |
|
|
|
266 |
df['unique_id']=1
|
|
|
|
|
|
|
267 |
st.session_state.ds_col = ds_col
|
268 |
st.session_state.y_col = y_col
|
269 |
|
@@ -273,10 +278,8 @@ def dynamic_forecasting():
|
|
273 |
dynamic_horizon = st.sidebar.number_input("Forecast horizon", value=18)
|
274 |
dynamic_max_steps = st.sidebar.number_input('Max steps', value=200)
|
275 |
|
276 |
-
df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
|
277 |
-
st.session_state.df = df
|
278 |
|
279 |
-
forecast_time_series(df, dynamic_model_choice, dynamic_horizon, dynamic_max_steps, ds_col='ds')
|
280 |
|
281 |
pg = st.navigation({
|
282 |
"Overview": [
|
|
|
164 |
nf.fit(df)
|
165 |
return model
|
166 |
|
167 |
+
def forecast_time_series(df, model_type, horizon, max_steps=200, ds_col='ds',y_col):
|
168 |
start_time = time.time() # Start timing
|
169 |
freq = determine_frequency(df, ds_col)
|
170 |
st.sidebar.write(f"Data frequency: {freq}")
|
|
|
177 |
forecast_results[model_type] = generate_forecast(model, df, tag='retrain')
|
178 |
|
179 |
for model_name, forecast_df in forecast_results.items():
|
180 |
+
plot_forecasts(forecast_df, df, f'{model_name} Forecast for {y_col}')
|
181 |
|
182 |
end_time = time.time() # End timing
|
183 |
time_taken = end_time - start_time
|
184 |
+
st.success(f"Time taken for {model_type} forecast: {time_taken:.2f} seconds")
|
185 |
|
186 |
@st.cache_data
|
187 |
def load_default():
|
|
|
218 |
|
219 |
df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
|
220 |
df['unique_id']=1
|
221 |
+
df = df[['unique_id','ds','y']]
|
222 |
st.session_state.df = df
|
223 |
|
224 |
# Determine frequency of data
|
|
|
240 |
forecast_results['TFT'] = generate_forecast(tft_model, df)
|
241 |
|
242 |
for model_name, forecast_df in forecast_results.items():
|
243 |
+
plot_forecasts(forecast_df, df, f'{model_name} Forecast for {y_col}')
|
244 |
|
245 |
end_time = time.time() # End timing
|
246 |
time_taken = end_time - start_time
|
247 |
+
st.success(f"Time taken for {model_choice} forecast: {time_taken:.2f} seconds")
|
248 |
|
249 |
def dynamic_forecasting():
|
250 |
st.title("Dynamic Forecasting")
|
|
|
264 |
y_col = st.selectbox("Select Target column", options=columns, index=columns.index('y') if 'y' in columns else 1)
|
265 |
# unique_id_col = st.text_input("Unique ID column (default: '1')", value="1")
|
266 |
|
267 |
+
df = df.rename(columns={ds_col: 'ds', y_col: 'y'})
|
268 |
df['unique_id']=1
|
269 |
+
df = df[['unique_id','ds','y']]
|
270 |
+
st.session_state.df = df
|
271 |
+
|
272 |
st.session_state.ds_col = ds_col
|
273 |
st.session_state.y_col = y_col
|
274 |
|
|
|
278 |
dynamic_horizon = st.sidebar.number_input("Forecast horizon", value=18)
|
279 |
dynamic_max_steps = st.sidebar.number_input('Max steps', value=200)
|
280 |
|
|
|
|
|
281 |
|
282 |
+
forecast_time_series(df, dynamic_model_choice, dynamic_horizon, dynamic_max_steps, ds_col='ds',y_col)
|
283 |
|
284 |
pg = st.navigation({
|
285 |
"Overview": [
|