arithescientist commited on
Commit
acf8d04
Β·
verified Β·
1 Parent(s): f3251fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -54,6 +54,7 @@ def insertintotable():
54
 
55
 
56
 
 
57
  def ARIMA_ALGO(df):
58
  # β€” 1) Ensure a DateTimeIndex β€”
59
  if 'Date' in df.columns:
@@ -79,12 +80,13 @@ def insertintotable():
79
  # β€” 4) Train/test split (65/35) β€”
80
  split = int(len(series) * 0.65)
81
  train, test = series.iloc[:split], series.iloc[split:]
82
-
83
  # β€” 5) Rolling ARIMA + 7-day ahead β€”
84
  history, preds_all = list(train), []
85
- for t in range(len(test) + 7):
86
- m = ARIMA(history, order=(6,1,0)).fit()
87
- yhat = float(m.forecast()[0])
 
88
  preds_all.append(yhat)
89
  history.append(test.iloc[t] if t < len(test) else yhat)
90
 
@@ -104,7 +106,6 @@ def insertintotable():
104
 
105
  return preds_all, rmse, tomorrow, history_df, predict_df
106
 
107
-
108
  # Run ARIMA
109
  preds, rmse, tomorrow, hist_df, pred_df = ARIMA_ALGO(df)
110
 
 
54
 
55
 
56
 
57
+
58
  def ARIMA_ALGO(df):
59
  # β€” 1) Ensure a DateTimeIndex β€”
60
  if 'Date' in df.columns:
 
80
  # β€” 4) Train/test split (65/35) β€”
81
  split = int(len(series) * 0.65)
82
  train, test = series.iloc[:split], series.iloc[split:]
83
+
84
  # β€” 5) Rolling ARIMA + 7-day ahead β€”
85
  history, preds_all = list(train), []
86
+ m = ARIMA(history, order=(6,1,0)).fit()
87
+ for t in range(len(test) + 7):
88
+ model = m.apply(history)
89
+ yhat = float(model.forecast()[0])
90
  preds_all.append(yhat)
91
  history.append(test.iloc[t] if t < len(test) else yhat)
92
 
 
106
 
107
  return preds_all, rmse, tomorrow, history_df, predict_df
108
 
 
109
  # Run ARIMA
110
  preds, rmse, tomorrow, hist_df, pred_df = ARIMA_ALGO(df)
111