Update app.py
Browse files182 unmodified lines1831841851861871861871881891901911921931931941951964 unmodified lines201202203204204205206207208209210211212213214215210211212213214215216217218182 unmodified lines
elif self.model_type == 'SARIMA': forecast = self.model.get_forecast(steps=days) return forecast.predicted_mean
return forecast.predicted_mean.values elif self.model_type == 'Prophet': future = self.model.make_future_dataframe(periods=days) for feature in ['SMA_20', 'EMA_20', 'RSI', 'BB_High', 'BB_Low']: future[feature] = self.data[feature].iloc[-1] # Use last known value forecast = self.model.predict(future) return forecast['yhat'][-days:].values return forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']][-days:]
elif self.model_type in ['XGBoost', 'RandomForest']: last_data = self.data[self.features].iloc[-1:].values4 unmodified lines # Update last_data for next prediction last_data = np.roll(last_data, -1, axis=1) last_data[0, -5] = pred[0] # Assuming 'Close' is the 5th from last feature return predictions return np.array(predictions)
except Exception as e: print(f"Error predicting with {self.model_type} model: {str(e)}") return None
def evaluate_model(self, test_data): predictions = self.predict(len(test_data)) mse = mean_squared_error(test_data['Close'], predictions) mape = mean_absolute_percentage_error(test_data['Close'], predictions) rmse = np.sqrt(mse) return mse, mape, rmse def evaluate_model(self, test_data): predictions = self.predict(len(test_data)) mse = mean_squared_error(test_data['Close'], predictions) mape = mean_absolute_percentage_error(test_data['Close'], predictions) rmse = np.sqrt(mse) return mse, mape, rmse
def fetch_stock_data(ticker): try:app.py+10-10