import yfinance as yf from sklearn.model_selection import train_test_split from xgboost import XGBRegressor from sklearn.metrics import mean_squared_error from math import sqrt import numpy as np import pandas as pd import streamlit as st inp = st.text_input('fak u') def predict_crypto_prices(): data = yf.download(inp, period='max') # Create a new "lagged" dataframe for the model data['Previous_Open'] = data['Open'].shift(1) data['Previous_Close'] = data['Close'].shift(1) data['Previous_Low'] = data['Low'].shift(1) data['Previous_High'] = data['High'].shift(1) # Drop the missing values created by shifting data = data.dropna() # Define inputs and outputs for each prediction features = ['Previous_Open', 'Previous_Close', 'Previous_Low', 'Previous_High'] predictions = ['Open', 'Close', 'Low', 'High'] predicted_prices = pd.DataFrame(columns=predictions) for feature, prediction in zip(features, predictions): X = data[feature].values.reshape(-1, 1) y = data[prediction].values # Split the data into training and testing datasets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Initialize XGBoost regressor model model = XGBRegressor(n_estimators=100, learning_rate=0.1, objective='reg:squarederror') # Train the model model.fit(X_train, y_train) # Make predictions test_predictions = model.predict(X_test) test_rmse = sqrt(mean_squared_error(y_test, test_predictions)) # Predict the future price using the most recent price latest_price = data[prediction].iloc[-1] # Reshape the input latest_price_reshaped = np.array(latest_price).reshape(1, -1) # Make prediction for the next day predicted_price = model.predict(latest_price_reshaped) predicted_prices[prediction] = predicted_price return predicted_prices predicted_prices = predict_crypto_prices() if button('Predict'): st.write(predicted_prices)