Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,33 +72,33 @@ def forecast_models(ticker="AAPL", test_len=180):
|
|
| 72 |
results['Prophet'] = {"error": str(e)}
|
| 73 |
|
| 74 |
# ====== LSTM (weights only) ======
|
| 75 |
-
try:
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
except Exception as e:
|
| 101 |
-
|
| 102 |
|
| 103 |
# ===== Plot comparison =====
|
| 104 |
plt.figure(figsize=(12,5))
|
|
@@ -139,8 +139,8 @@ demo = gr.Interface(
|
|
| 139 |
gr.Image(type="filepath", label="Forecast Plot"),
|
| 140 |
gr.Dataframe(label="Performance Metrics")
|
| 141 |
],
|
| 142 |
-
title="📈 Stock Price Forecasting (ARIMA, Prophet
|
| 143 |
-
description="This app compares ARIMA, Prophet
|
| 144 |
)
|
| 145 |
|
| 146 |
if __name__ == "__main__":
|
|
|
|
| 72 |
results['Prophet'] = {"error": str(e)}
|
| 73 |
|
| 74 |
# ====== LSTM (weights only) ======
|
| 75 |
+
# try:
|
| 76 |
+
# scaler = joblib.load("scaler.pkl")
|
| 77 |
+
# lstm_model = build_lstm(window_size=60)
|
| 78 |
+
# lstm_model.load_weights("lstm_model.weights.h5") # ✅ weights-only loading
|
| 79 |
|
| 80 |
+
# scaled_series = scaler.transform(series.values.reshape(-1,1))
|
| 81 |
|
| 82 |
+
# window_size = 60
|
| 83 |
+
# X = []
|
| 84 |
+
# for i in range(window_size, len(scaled_series)):
|
| 85 |
+
# X.append(scaled_series[i-window_size:i,0])
|
| 86 |
+
# X = np.array(X).reshape((-1, window_size, 1))
|
| 87 |
|
| 88 |
+
# split_index = len(train) - window_size
|
| 89 |
+
# X_test = X[split_index:]
|
| 90 |
|
| 91 |
+
# pred_scaled = lstm_model.predict(X_test, verbose=0)
|
| 92 |
+
# pred = scaler.inverse_transform(pred_scaled)
|
| 93 |
+
# lstm_forecast = pd.Series(pred.flatten(), index=test.index[:len(pred)])
|
| 94 |
+
|
| 95 |
+
# results['LSTM'] = {
|
| 96 |
+
# "forecast": lstm_forecast,
|
| 97 |
+
# "RMSE": rmse(test[:len(pred)], lstm_forecast),
|
| 98 |
+
# "MAPE": mean_absolute_percentage_error(test[:len(pred)], lstm_forecast)
|
| 99 |
+
# }
|
| 100 |
+
# except Exception as e:
|
| 101 |
+
# results['LSTM'] = {"error": str(e)}
|
| 102 |
|
| 103 |
# ===== Plot comparison =====
|
| 104 |
plt.figure(figsize=(12,5))
|
|
|
|
| 139 |
gr.Image(type="filepath", label="Forecast Plot"),
|
| 140 |
gr.Dataframe(label="Performance Metrics")
|
| 141 |
],
|
| 142 |
+
title="📈 Stock Price Forecasting (ARIMA, Prophet)",
|
| 143 |
+
description="This app compares ARIMA, Prophet models on stock closing prices using RMSE & MAPE."
|
| 144 |
)
|
| 145 |
|
| 146 |
if __name__ == "__main__":
|