samarthv commited on
Commit
b4b6e66
1 Parent(s): 9acfa7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -1,30 +1,33 @@
1
  import streamlit as st
2
  import pandas as pd
 
3
  from sklearn.linear_model import LinearRegression
 
4
 
5
- # Load the dataset
6
- data = pd.read_csv('Google_test_data.csv')
7
 
8
- # Split the data into features and target
9
- X = data[['Open', 'High', 'Low', 'Volume']]
10
  y = data['Close']
11
 
12
- # Train the model
13
  model = LinearRegression()
14
  model.fit(X, y)
15
 
16
- # Streamlit app
17
- st.title('Google Stock Price Prediction')
18
 
19
- # Input form for user to enter values
20
- open_price = st.number_input('Enter the opening price:')
21
- high_price = st.number_input('Enter the high price:')
22
- low_price = st.number_input('Enter the low price:')
23
- volume = st.number_input('Enter the volume:')
 
 
24
 
25
- # Make prediction
26
- predicted_close = model.predict([[open_price, high_price, low_price, volume]])
27
 
28
- # Display the prediction
29
- st.subheader('Predicted Close Price')
30
- st.write(predicted_close[0])
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import numpy as np
4
  from sklearn.linear_model import LinearRegression
5
+ import matplotlib.pyplot as plt
6
 
7
+ # Load the stock data from the CSV file
8
+ data = pd.read_csv('google_stock.csv')
9
 
10
+ # Prepare the data for prediction
11
+ X = np.arange(len(data)).reshape(-1, 1)
12
  y = data['Close']
13
 
14
+ # Train the linear regression model
15
  model = LinearRegression()
16
  model.fit(X, y)
17
 
18
+ # Predict the stock prices
19
+ predictions = model.predict(X)
20
 
21
+ # Plot the actual and predicted stock prices
22
+ plt.plot(data['Date'], y, label='Actual')
23
+ plt.plot(data['Date'], predictions, label='Predicted')
24
+ plt.xlabel('Date')
25
+ plt.ylabel('Stock Price')
26
+ plt.title('Google Stock Price Prediction')
27
+ plt.legend()
28
 
29
+ # Remove the Streamlit default layout
30
+ st.set_page_config(layout="wide")
31
 
32
+ # Display the graph in Streamlit
33
+ st.pyplot(plt)