scikit-learn regression

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from sklearn import datasets
boston = datasets.load_boston()
x= boston.data
y= boston.targe
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=666)
from sklearn import linear_model
clf = linear_model.LinearRegression()
clf.fit(x_train,y_train)
y_predict = clf.predict(x_test)
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
MSE = mean_squared_error(y_test,y_predict)
print(MSE)
MAE = mean_absolute_error(y_test,y_predict)
print(MAE)