线性回归模型

 

1. 读取数据集

2. 训练集与测试集划分

from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split data = load_boston() x_train,x_test,y_train,y_test = train_test_split(data.data,data.target,test_size=0.3) print(x_train.shape,y_train.shape)

3. 线性回归模型:建立13个变量与房价之间的预测模型,并检测模型好坏。

复制代码
from sklearn.linear_model import LinearRegression
mlr = LinearRegression()
mlr.fit(x_train,y_train)
print('系数',mlr.coef_,"\n截距",mlr.intercept_) from sklearn.metrics import regression y_predict = mlr.predict(x_test) print("预测的均方误差:", regression.mean_squared_error(y_test,y_predict)) print("预测的平均绝对误差:", regression.mean_absolute_error(y_test,y_predict)) print("模型的分数:",mlr.score(x_test, y_test))
复制代码

你可能感兴趣的:(线性回归模型)