Delete app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import streamlit as stimport yfinance as yfimport numpy as npimport pandas as pdfrom sklearn.model_selection import train_test_splitfrom sklearn.preprocessing import StandardScalerfrom xgboost import XGBRegressorfrom sklearn.metrics import mean_squared_errorimport math
text_input = st.text_input('Enter the crypto currency pair e.g., BTC-USD:')
# Fetch historical data for BTC-USDif text_input: data = yf.download(text_input, period='max')
# Select relevant features data = data[['Open', 'High', 'Low', 'Close']]
# Create a new "lagged" dataframe for the model data['Previous_Close'] = data['Close'].shift(1)
# Drop the missing values created by shifting data = data.dropna()
# Standardize the data scaler = StandardScaler() data_scaled = pd.DataFrame(scaler.fit_transform(data), columns=data.columns)
# Define inputs and outputs X = data_scaled.drop('Close', axis=1).values y = data_scaled['Close'].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)
# Evaluate the model train_predictions = model.predict(X_train) train_rmse = math.sqrt(mean_squared_error(y_train, train_predictions))
test_predictions = model.predict(X_test) test_rmse = math.sqrt(mean_squared_error(y_test, test_predictions))
# Predict tomorrow's close price using the most recent data latest_data = data.iloc[-1] latest_data_reshaped = np.array(scaler.transform([latest_data])).reshape(1, -1)
# Make prediction and inverse the scaling for the predicted close price predicted_close_scaled = model.predict(latest_data_reshaped) predicted_close = scaler.inverse_transform(predicted_close_scaled.reshape(-1, 1)) #return predicted_close[0] if st.button('say'): st.write(latest_data['Close'])
if st.button('PediCrypto'): #st.write('کمی بیسه کوزت') st.write(predicted_close[0]) #st.write(latest_data['Close'])app.pyDeleted-65