波士顿房价数据集——随机森林

波士顿房价数据链接:https://pan.baidu.com/s/1JPrcNl1AgNCKEHCjOGyHvQ 
提取码:1234

import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn import metrics  #评价函数库
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestRegressor #导入随机森林
from sklearn.model_selection import GridSearchCV  #网格搜索验证
from sklearn import tree 
import pydotplus #绘制随机森林
from IPython.display import Image,display #显示图像
%matplotlib inline  #在当前环境中显示图像
df = pd.read_csv("D:/波士顿房价预测/boston_housing_data.csv")
df.dropna(inplace=True)  #消除空值
x = df.drop(["MEDV"],axis = 1)  #x选取前13个特征
y = df["MEDV"]  #y选取房价
x_train,x_test,y_train,y_test = train_test_split(x,y,random_state = 0)
#定义网格搜索
param_grid = {
    "n_estimators":[5,10,20,100,200],   #数值均可预设
    "max_depth":[3,5,7],
    "max_features":[0.6,0.7,0.8,1]
}
  • 0
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值