1、导入sklearn数据库
2、导入数据库的数据
3、数据分析
def linear_model1():
data=load_boston()
print(data.data)
print(data.target)
x_train, x_test, y_train, y_test = train_test_split(data.data, data.target,random_state=22)
transfer = StandardScaler()
x_train = transfer.fit_transform(x_train)
x_test = transfer.fit_transform(x_test)
estimator = LinearRegression()
estimator.fit(x_train, y_train)
y_predict = estimator.predict(x_test)
print("预测值为:\n", y_predict)
print("模型中的系数为:\n", estimator.coef_)
print("模型中的偏置为:\n", estimator.intercept_)
error = mean_squared_error(y_test, y_predict)
print("误差为:\n", error)
return None
4、输出结果
学号:202113430104万熙