#导入波士顿数据
from sklearn.datasets import load_boston
import pandas as pd
import numpy as np
boston=load_boston()
print(boston.data.shape)
print(boston.target.shape)
#数据集的描述
print(boston.feature_names)
#print(boston.DESCR)
#特征
bostonDf_X = pd.DataFrame(boston.data,columns = boston.feature_names)
bostonDf_X.head()
#标签
bostonDf_y = pd.DataFrame(boston.target,columns=['housePrice'])#【注意加列名要加在[]中】
bostonDf_y.head()
#合并DataFrame
bostonDf = pd.concat([bostonDf_X,bostonDf_y],axis =1)#axis =1 为横向操作,即横向合并
bostonDf.shape#506,14
bostonDf.head()
#RM房间数 MEDV 房价
#创建用于模型的数据集
from sklearn.model_selection import train_test_split #切分训练集与测试集
#划分训练集与测试集7:3比例
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.3,random_state=0)
print(len(x_train))
print(len(x_test))
from sklearn.model_selection import train_test_split #切分训练集与测试集
from sklearn.linear_model import LinearRegression #线性回归模型
LR=LinearRegression()
#特征
bo
多变量线性回归的python实现-(数据标准化以及网格搜索调参)
最新推荐文章于 2024-07-12 02:07:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)