Update app.py
Browse files12 unmodified lines1314151617181912 unmodified linessession = Session()def give_integer_data():# Define the table using the Declarative approachclass DateTimeData(Base):12 unmodified lines13141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596012 unmodified linessession = Session()def give_integer_data():data = yf.download('BTC-USD', period='max')#start="2019-01-01", end="2023-12-28")# Select Open and Close pricedata = data[['Open', 'Close']]#print(data)# Create a new "lagged" dataframe for the modeldata['Previous_Close'] = data['Close'].shift(1)# Drop the missing values created by shiftingdata = data.dropna()# Define inputs and outputsX = data['Previous_Close'].values.reshape(-1, 1)y = data['Close'].values# Split the data into training and testing datasetsX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)# Initialize XGBoost regressor modelmodel = XGBRegressor(n_estimators=100, learning_rate=0.1, objective='reg:squarederror')# Train the modelmodel.fit(X_train, y_train)# Evaluate the modeltrain_predictions = model.predict(X_train)train_rmse = sqrt(mean_squared_error(y_train, train_predictions))#print(f"Train RMSE: {train_rmse}")test_predictions = model.predict(X_test)test_rmse = sqrt(mean_squared_error(y_test, test_predictions))#print(f"Test RMSE: {test_rmse}")# Predict tomorrow's close price using the most recent close pricelatest_close = data['Close'].iloc[-1]# Reshape the inputlatest_close_reshaped = np.array(latest_close).reshape(1, -1)# Make predictionpredicted_close = model.predict(latest_close_reshaped)return predicted_close# Define the table using the Declarative approachclass DateTimeData(Base):
app.py+41