rasel-harun commited on
Commit
971a0d9
·
verified ·
1 Parent(s): a361a2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -4,7 +4,6 @@ import numpy as np
4
  import matplotlib.pyplot as plt
5
  import yfinance as yf
6
  import joblib
7
- import pickle
8
  from tensorflow.keras.models import Sequential
9
  from tensorflow.keras.layers import LSTM, Dense, Dropout
10
  from sklearn.metrics import mean_squared_error, mean_absolute_percentage_error
@@ -25,7 +24,7 @@ def download_data(ticker, start="2015-01-01", end=None):
25
  df.rename(columns={'Close': 'close'}, inplace=True)
26
  return df
27
 
28
- # ===== LSTM architecture =====
29
  def build_lstm(window_size=60):
30
  model = Sequential([
31
  LSTM(64, return_sequences=True, input_shape=(window_size,1)),
@@ -46,8 +45,7 @@ def run_app(ticker):
46
 
47
  # ===== ARIMA =====
48
  try:
49
- with open("arima_model.pkl", "rb") as f:
50
- arima_model = pickle.load(f)
51
  arima_forecast = arima_model.forecast(steps=30)
52
  arima_rmse = np.sqrt(mean_squared_error(stock_data['Close'][-30:], arima_forecast))
53
  arima_mape = mean_absolute_percentage_error(stock_data['Close'][-30:], arima_forecast)
@@ -57,8 +55,7 @@ def run_app(ticker):
57
 
58
  # ===== Prophet =====
59
  try:
60
- with open("prophet_model.pkl", "rb") as f:
61
- prophet_model = pickle.load(f)
62
  prophet_future = prophet_model.make_future_dataframe(periods=30)
63
  prophet_forecast = prophet_model.predict(prophet_future)
64
  prophet_forecast = prophet_forecast.set_index("ds").loc[stock_data.index[-30:]]
@@ -70,7 +67,7 @@ def run_app(ticker):
70
 
71
  # ===== Results Table =====
72
  df_results = pd.DataFrame(results, columns=["Model", "RMSE", "MAPE"])
73
- df_results = df_results.dropna(how="all") # remove any empty rows
74
 
75
  # ===== Plot =====
76
  plt.figure(figsize=(10, 5))
 
4
  import matplotlib.pyplot as plt
5
  import yfinance as yf
6
  import joblib
 
7
  from tensorflow.keras.models import Sequential
8
  from tensorflow.keras.layers import LSTM, Dense, Dropout
9
  from sklearn.metrics import mean_squared_error, mean_absolute_percentage_error
 
24
  df.rename(columns={'Close': 'close'}, inplace=True)
25
  return df
26
 
27
+ # ===== LSTM architecture (future use) =====
28
  def build_lstm(window_size=60):
29
  model = Sequential([
30
  LSTM(64, return_sequences=True, input_shape=(window_size,1)),
 
45
 
46
  # ===== ARIMA =====
47
  try:
48
+ arima_model = joblib.load("arima_model.pkl")
 
49
  arima_forecast = arima_model.forecast(steps=30)
50
  arima_rmse = np.sqrt(mean_squared_error(stock_data['Close'][-30:], arima_forecast))
51
  arima_mape = mean_absolute_percentage_error(stock_data['Close'][-30:], arima_forecast)
 
55
 
56
  # ===== Prophet =====
57
  try:
58
+ prophet_model = joblib.load("prophet_model.pkl")
 
59
  prophet_future = prophet_model.make_future_dataframe(periods=30)
60
  prophet_forecast = prophet_model.predict(prophet_future)
61
  prophet_forecast = prophet_forecast.set_index("ds").loc[stock_data.index[-30:]]
 
67
 
68
  # ===== Results Table =====
69
  df_results = pd.DataFrame(results, columns=["Model", "RMSE", "MAPE"])
70
+ df_results = df_results.dropna(how="all") # remove empty rows
71
 
72
  # ===== Plot =====
73
  plt.figure(figsize=(10, 5))