-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths9.py
More file actions
36 lines (23 loc) · 853 Bytes
/
s9.py
File metadata and controls
36 lines (23 loc) · 853 Bytes
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
import pandas as pd
from sklearn.linear_model import LinearRegression
import numpy as np
data = pd.read_csv('q9.csv')
data['Open'] = data['Open'].astype(float)
data['High'] = data['High'].astype(float)
data['Low'] = data['Low'].astype(float)
data['Close'] = data['Close'].astype(float)
data['Date'] = pd.to_datetime(data['Date'])
data = data.sort_values('Date')
X = []
y = []
for i in range(len(data) - 1):
X.append([data['Open'].iloc[i], data['High'].iloc[i], data['Low'].iloc[i], data['Close'].iloc[i]])
y.append(data['Close'].iloc[i + 1])
X = np.array(X)
y = np.array(y)
model = LinearRegression()
model.fit(X, y)
last_day_features = [data['Open'].iloc[-1], data['High'].iloc[-1], data['Low'].iloc[-1], data['Close'].iloc[-1]]
predicted_price = model.predict([last_day_features])[0]
print(f"{predicted_price:.2f}")
#print(398.03)