2019-01-31
阅读量:
852
R语言构建分类回归树
回归决策树:用于预测定量数据,响应预测值取它所属的叶节点内训练集的平均响应值。
构造过程:特征选择→决策树的生成→决策树的剪枝
回归树RSS作为确定分割点的准则
#####回归树####
library(MASS)
data("Boston")
set.seed(1)
train=sample(1:nrow(Boston),nrow(Boston)/2)
tree.boston=tree(medv~.,Boston,subset=train) #房价中位数
plot(tree.boston)
text(tree.boston,pretty=0)
cv.boston=cv.tree(tree.boston)
plot(cv.bostonsize,cv.bostondev,type="b")
prune.boston=prune.tree(tree.boston,best=5)
plot(prune.boston)
text(prune.boston,pretty=0)
yhat=predict(tree.boston,newdata = Boston[-train,])
boston.test=Boston[-train,"medv"]
plot(yhat,boston.test)
abline(0,1)
mean((yhat-boston.test)^2) #25






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
1条评论