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.
决策树_实战_波士顿房价
最新推荐文章于 2023-05-15 13:51:09 发布
这篇博客深入探讨了如何运用决策树算法进行机器学习实战,以预测波士顿地区的房价。通过详尽的数据预处理和特征选择,构建并训练了决策树模型,展示了模型在房价预测上的性能和解释能力。
摘要由CSDN通过智能技术生成