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

本文探讨了如何运用sklearn库中的随机森林算法,对著名的波士顿房价数据集进行分析,旨在预测房价并揭示影响房价的关键因素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

波士顿房价数据链接: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]
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值