Update app.py
Browse files182 unmodified lines1831841851861871881891901911921931941951964 unmodified lines201202203204205206207208209210211212213214215216217218182 unmodified lineselif self.model_type == 'SARIMA':forecast = self.model.get_forecast(steps=days)return forecast.predicted_meanelif 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 valueforecast = self.model.predict(future)return forecast['yhat'][-days:].valueselif self.model_type in ['XGBoost', 'RandomForest']:last_data = self.data[self.features].iloc[-1:].values4 unmodified lines# Update last_data for next predictionlast_data = np.roll(last_data, -1, axis=1)last_data[0, -5] = pred[0] # Assuming 'Close' is the 5th from last featurereturn predictionsexcept Exception as e:print(f"Error predicting with {self.model_type} model: {str(e)}")return Nonedef 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, rmsedef fetch_stock_data(ticker):try:182 unmodified lines1831841851861871881891901911921931941951964 unmodified lines201202203204205206207208209210211212213214215216217218182 unmodified lineselif self.model_type == 'SARIMA':forecast = self.model.get_forecast(steps=days)return forecast.predicted_mean.valueselif 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 valueforecast = self.model.predict(future)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 predictionlast_data = np.roll(last_data, -1, axis=1)last_data[0, -5] = pred[0] # Assuming 'Close' is the 5th from last featurereturn np.array(predictions)except Exception as e:print(f"Error predicting with {self.model_type} model: {str(e)}")return Nonedef 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, rmsedef fetch_stock_data(ticker):try:
app.py+10-10