-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
22 lines (15 loc) · 719 Bytes
/
Copy pathmain.py
File metadata and controls
22 lines (15 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import numpy as np
from sklearn.linear_model import LinearRegression
#the input, x, and the output, y. You should call .reshape() on x because this array must be two-dimensional,
# or more precisely, it must have one column and as many rows as necessary. That’s exactly what the argument (-1, 1)
#of .reshape() specifies.
x = np.array([5, 15, 25, 35, 45, 55]).reshape((-1, 1))
y = np.array([5, 20, 14, 32, 22, 38])
model = LinearRegression()
model = LinearRegression().fit(x, y)
r_sq = model.score(x, y)
print(f"coefficient of determination: {r_sq}")
print(f"intercept: {model.intercept_}")
print(f"slope: {model.coef_}")
y_pred = model.predict(x)
print(f"predicted response:\n{y_pred}")