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
| from sklearn.datasets import load_boston data = load_boston() x = data['data'] y = data['target']
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 = ...)
X_train.shape
from sklearn.linear_model import LinearRegression
clf = LinearRegression() clf.fit(X_train,y_train) clf.coef_
y_train_pred = clf.predict(X_train) y_test_pred = clf.predict(X_test)
from sklearn.metrics import mean_squared_error mean_squared_error(y_train,y_train_pred) mean_squared_error(y_test,y_test_pred)
from sklearn.metrics import r2_score r2_score(y_train,y_train_pred) r2_score(y_test,y_test_pred)
from sklearn.metrics import mean_absolute_error mean_absolute_error(y_train,y_train_pred) mean_absolute_error(y_test,y_test_pred)
|