Spaces:
Sleeping
Sleeping
File size: 2,043 Bytes
d8c1d78 f558d11 b4b6e66 d8c1d78 b4b6e66 f558d11 71af6f7 ad28108 b56a9d4 ad28108 a57a319 ad28108 f558d11 b4b6e66 ad28108 f558d11 b4b6e66 d8c1d78 5b1bbef a57a319 5b1bbef a57a319 238ed09 a57a319 238ed09 a57a319 238ed09 a57a319 238ed09 a57a319 238ed09 a57a319 238ed09 a57a319 238ed09 a57a319 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import streamlit as st
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
# Remove the Streamlit default layout
st.set_page_config(layout="wide")
# Load the stock data from the CSV files
data1 = pd.read_csv('Google_test_data.csv')
data2 = pd.read_csv('tesla.csv')
# Combine the datasets into a dictionary
datasets = {'Google': data1, 'Tesla': data2}
# Get the user's dataset selection
selected_dataset = st.selectbox('Select Stock', list(datasets.keys()))
# Retrieve the selected dataset
selected_data = datasets[selected_dataset]
# Prepare the data for prediction
X = np.arange(len(selected_data)).reshape(-1, 1)
y = selected_data['Close']
# Train the linear regression model
model = LinearRegression()
model.fit(X, y)
# Define a flag for displaying the graphs
display_graphs = False
# Create a submit button
if st.button('Submit'):
display_graphs = True
# Display the graphs if the submit button is clicked
if display_graphs:
# Create subplots
fig, axes = plt.subplots(3, 1, figsize=(10, 15))
# Plot 1: Actual and Predicted Stock Prices
axes[0].plot(selected_data['Date'], y, label='Actual')
axes[0].plot(selected_data['Date'], model.predict(X), label='Predicted')
axes[0].set_xlabel('Date')
axes[0].set_ylabel('Stock Price')
axes[0].set_title(f'{selected_dataset} Stock Price Prediction')
axes[0].legend()
# Plot 2: Volume of Trades
axes[1].plot(selected_data['Date'], selected_data['Volume'])
axes[1].set_xlabel('Date')
axes[1].set_ylabel('Volume')
axes[1].set_title(f'{selected_dataset} Volume of Trades')
# Plot 3: Daily Percentage Change in Stock Prices
daily_returns = selected_data['Close'].pct_change() * 100
axes[2].plot(selected_data['Date'], daily_returns)
axes[2].set_xlabel('Date')
axes[2].set_ylabel('Percentage Change')
axes[2].set_title(f'{selected_dataset} Daily Percentage Change in Stock Prices')
# Display the graphs in Streamlit
st.pyplot(fig)
|