samarthv commited on
Commit
d8c1d78
1 Parent(s): f558d11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -70
app.py CHANGED
@@ -1,78 +1,30 @@
1
- import numpy as np
2
  import pandas as pd
3
- import matplotlib.pyplot as plt
4
- from sklearn.preprocessing import MinMaxScaler
5
- from keras.models import Sequential
6
- from keras.layers import Dense, LSTM, Dropout
7
 
8
- data = pd.read_csv('Google_train_data.csv')
9
- data["Close"] = pd.to_numeric(data.Close, errors='coerce')
10
- data = data.dropna()
11
- trainData = data.iloc[:, 4:5].values
12
 
13
- sc = MinMaxScaler(feature_range=(0, 1))
14
- trainData = sc.fit_transform(trainData)
 
15
 
16
- X_train = []
17
- y_train = []
 
18
 
19
- for i in range(60, 1149): # 60: timestep // 1149: length of the data
20
- X_train.append(trainData[i - 60:i, 0])
21
- y_train.append(trainData[i, 0])
22
 
23
- X_train, y_train = np.array(X_train), np.array(y_train)
24
- X_train = np.reshape(X_train, (X_train.shape[0], X_train.shape[1], 1))
 
 
 
25
 
26
- model = Sequential()
27
- model.add(LSTM(units=100, return_sequences=True, input_shape=(X_train.shape[1], 1)))
28
- model.add(Dropout(0.2))
29
 
30
- model.add(LSTM(units=100, return_sequences=True))
31
- model.add(Dropout(0.2))
32
-
33
- model.add(LSTM(units=100, return_sequences=True))
34
- model.add(Dropout(0.2))
35
-
36
- model.add(LSTM(units=100, return_sequences=False))
37
- model.add(Dropout(0.2))
38
-
39
- model.add(Dense(units=1))
40
-
41
- model.compile(optimizer='adam', loss="mean_squared_error")
42
- hist = model.fit(X_train, y_train, epochs=20, batch_size=32, verbose=2)
43
-
44
- plt.plot(hist.history['loss'])
45
- plt.title('Training model loss')
46
- plt.ylabel('loss')
47
- plt.xlabel('epoch')
48
- plt.legend(['train'], loc='upper left')
49
- plt.show()
50
-
51
- testData = pd.read_csv('Google_test_data.csv')
52
- testData["Close"] = pd.to_numeric(testData.Close, errors='coerce')
53
- testData = testData.dropna()
54
- testData = testData.iloc[:, 4:5]
55
- y_test = testData.iloc[60:, 0:].values
56
-
57
- # input array for the model
58
- inputClosing = testData.iloc[:, 0:].values
59
- inputClosing_scaled = sc.transform(inputClosing)
60
-
61
- X_test = []
62
- length = len(testData)
63
- timestep = 60
64
-
65
- for i in range(timestep, length):
66
- X_test.append(inputClosing_scaled[i - timestep:i, 0])
67
-
68
- X_test = np.array(X_test)
69
- y_pred = model.predict(X_test)
70
- predicted_price = sc.inverse_transform(y_pred)
71
-
72
- plt.plot(y_test, color='red', label='Actual Stock Price')
73
- plt.plot(predicted_price, color='green', label='Predicted Stock Price')
74
- plt.title('Google stock price prediction')
75
- plt.xlabel('Time')
76
- plt.ylabel('Stock Price')
77
- plt.legend()
78
- plt.show()
 
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_stock.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])