-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_reg.py
More file actions
43 lines (33 loc) · 1016 Bytes
/
linear_reg.py
File metadata and controls
43 lines (33 loc) · 1016 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
37
38
39
40
41
42
43
from sklearn import linear_model, datasets
from sklearn.model_selection import train_test_split
import numpy as np
import seaborn as sns
# from sklearn.metrics import accuracy_score
from matplotlib import pyplot as plt
boston = datasets.load_boston()
X = boston.data
y = boston.target
# print("X")
# print(X)
# print(X.shape)
# print("y")
# print(y)
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.5)
# algo / model
li_reg = linear_model.LinearRegression()
# visualize the data
# plt.scatter(X.T[5], y)
# plt.scatter(X.T[3], y)
# plt.scatter(X.T[7], y)
# plt.show()
model = li_reg.fit(X_train, y_train)
prediction = model.predict(X_test)
# accuracy = accuracy_score(y_test, prediction)
print("Prediction: ", prediction)
print("R^2: ", li_reg.score(X, y))
print("coef: ", li_reg.coef_)
# print("Accuracy: ", accuracy)
print("Intercept: ", li_reg.intercept_)
# a = int(input("Enter a Number to Predict: "))
# print("Prediction: ", model.predict(X)[a])
# print("Accutal Value: ", y[a])