Johan713 commited on
Commit
dfc4ebf
·
verified ·
1 Parent(s): 38753df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -183,14 +183,14 @@ class StockPredictor:
183
 
184
  elif self.model_type == 'SARIMA':
185
  forecast = self.model.get_forecast(steps=days)
186
- return forecast.predicted_mean
187
-
188
  elif self.model_type == 'Prophet':
189
  future = self.model.make_future_dataframe(periods=days)
190
  for feature in ['SMA_20', 'EMA_20', 'RSI', 'BB_High', 'BB_Low']:
191
  future[feature] = self.data[feature].iloc[-1] # Use last known value
192
  forecast = self.model.predict(future)
193
- return forecast['yhat'][-days:].values
194
 
195
  elif self.model_type in ['XGBoost', 'RandomForest']:
196
  last_data = self.data[self.features].iloc[-1:].values
@@ -201,18 +201,18 @@ class StockPredictor:
201
  # Update last_data for next prediction
202
  last_data = np.roll(last_data, -1, axis=1)
203
  last_data[0, -5] = pred[0] # Assuming 'Close' is the 5th from last feature
204
- return predictions
205
 
206
  except Exception as e:
207
  print(f"Error predicting with {self.model_type} model: {str(e)}")
208
  return None
209
 
210
- def evaluate_model(self, test_data):
211
- predictions = self.predict(len(test_data))
212
- mse = mean_squared_error(test_data['Close'], predictions)
213
- mape = mean_absolute_percentage_error(test_data['Close'], predictions)
214
- rmse = np.sqrt(mse)
215
- return mse, mape, rmse
216
 
217
  def fetch_stock_data(ticker):
218
  try:
 
183
 
184
  elif self.model_type == 'SARIMA':
185
  forecast = self.model.get_forecast(steps=days)
186
+ return forecast.predicted_mean.values
187
+
188
  elif self.model_type == 'Prophet':
189
  future = self.model.make_future_dataframe(periods=days)
190
  for feature in ['SMA_20', 'EMA_20', 'RSI', 'BB_High', 'BB_Low']:
191
  future[feature] = self.data[feature].iloc[-1] # Use last known value
192
  forecast = self.model.predict(future)
193
+ return forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']][-days:]
194
 
195
  elif self.model_type in ['XGBoost', 'RandomForest']:
196
  last_data = self.data[self.features].iloc[-1:].values
 
201
  # Update last_data for next prediction
202
  last_data = np.roll(last_data, -1, axis=1)
203
  last_data[0, -5] = pred[0] # Assuming 'Close' is the 5th from last feature
204
+ return np.array(predictions)
205
 
206
  except Exception as e:
207
  print(f"Error predicting with {self.model_type} model: {str(e)}")
208
  return None
209
 
210
+ def evaluate_model(self, test_data):
211
+ predictions = self.predict(len(test_data))
212
+ mse = mean_squared_error(test_data['Close'], predictions)
213
+ mape = mean_absolute_percentage_error(test_data['Close'], predictions)
214
+ rmse = np.sqrt(mse)
215
+ return mse, mape, rmse
216
 
217
  def fetch_stock_data(ticker):
218
  try: