决策树_实战_波士顿房价

这篇博客深入探讨了如何运用决策树算法进行机器学习实战,以预测波士顿地区的房价。通过详尽的数据预处理和特征选择,构建并训练了决策树模型,展示了模型在房价预测上的性能和解释能力。
摘要由CSDN通过智能技术生成
import numpy as np
import sklearn.datasets as sd
import pandas as pd
import matplotlib.pyplot as plt

boston = sd.load_boston()
boston.keys()

boston.filename

print(boston.DESCR)

print(boston.feature_names)

print(boston.data.shape)#x

boston.target.shape

#划分训练集和测试集
import sklearn.model_selection as ms

x = boston.data
y = boston.target

train_x,\
test_x,\
train_y,\
test_y = ms.train_test_split(x,y,test_size=0.1,random_state=7)

res = ms.train_test_split(x,y,test_size=0.1,random_state=7)
res[0].shape#训练集输入数据
res[1].shape# 测试集输入数据
res[2].shape# 训练集输出数据
res[3].shape# 测试集输出数据

#构建决策树模型
import sklearn.tree as st 
import sklearn.metrics as sm

model = st.DecisionTreeRegressor(max_depth=6)
model.fit(train_x,train_y)
pred_test_y = model.predict(test_x)
pred_test_y

sm.r2_score(test_y,pred_test_y)

# Adaboost
import sklearn.tree as st
import sklearn.ensemble as se
model = st.DecisionTreeRegressor(max_depth=4)
model = se.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值