-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoston.py
More file actions
37 lines (25 loc) · 697 Bytes
/
Boston.py
File metadata and controls
37 lines (25 loc) · 697 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
#MULTIPLE LINEAR REGRESSION
#import libraries
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
import pandas as pd
#read file
d = pd.read_csv("/Users/subhangisati/Downloads/boston.csv")
d.head()
d.info()
x = d.iloc[:, :3]#all parameters of x
x.info()
y = d.iloc[:, 3]
y.info()
#split the data
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3)
#apply linear regression
model = LinearRegression()
#train
model.fit(x_train, y_train)
#test
lab_pred = model.predict(x_test)
#Accuracy
accuracy = model.score(x_test, y_test)
print("Accuracy :", accuracy*100, "%")