Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
6 |
-
data = pd.read_csv('
|
7 |
|
8 |
-
#
|
9 |
-
X = data
|
10 |
y = data['Close']
|
11 |
|
12 |
-
# Train the model
|
13 |
model = LinearRegression()
|
14 |
model.fit(X, y)
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
|
28 |
-
# Display the
|
29 |
-
st.
|
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)
|
|