gpt4 book ai didi

r - 如何从回归树 rpart 对象生成预测区间?

转载 作者:行者123 更新时间:2023-12-04 03:51:03 26 4
gpt4 key购买 nike

如何从使用 rpart 拟合的回归树生成预测区间?

我的理解是回归树以叶节点的平均值为条件对响应进行建模。我不知道如何从模型中获取叶节点的方差,但我想做的是使用叶节点的均值和方差进行模拟以获得预测区间。

Predict.rpart()不提供间隔选项。

示例:我用虹膜数据拟合了一棵树,但预测没有选项,“间隔”

> r1 <- rpart(Sepal.Length ~ ., cp = 0.001, data = iris[1:nrow(iris)-1,])
> predict(r1,newdata=iris[nrow(iris),],type = "interval")
Error in match.arg(type) :
'arg' should be one of “vector”, “prob”, “class”, “matrix”

最佳答案

我不清楚置信区间对回归树意味着什么,因为它们不是线性模型等经典统计模型。我主要看到两种用途:表征树的确定性或表征树每片叶子的预测精度。以下是对这些可能性中的每一种的答案。

表征树的确定性

如果您正在寻找 split 节点的置信度值,则 party直接提供,因为它使用置换测试并从统计上确定哪些变量最重要,以及每个分割的 p 值。 party的显着优势的 ctree函数结束 rpart如解释 here .

回归树的集合叶子的置信区间

第三,如果您正在寻找每个叶中值的区间置信度,那么叶中观测值的 [0.025,0.975] 分位数区间很可能就是您要查找的。 party 中的默认绘图在显示每个叶子的输出值的箱线图时采用类似的方法:

library("party")
r2 <- ctree(Sepal.Length ~ .,data=iris)
plot(r2)

example party tree

检索相应的间隔可以简单地通过以下方式完成:
iris$leaf <- predict(r2, type="node")
CIleaf <- aggregate(iris$Sepal.Length,
by=list(leaf=iris$leaf),
quantile,
prob=c(0.025, 0.25, 0.75, 0.975))

而且很容易形象化:
plot(as.factor(CIleaf$leaf), CIleaf[, 2],
ylab="Sepal length", xlab="Regression tree leaf")
legend("bottomright",
c(" 0.975 quantile", " 0.75 quantile", " mean",
" 0.25 quantile", " 0.025 quantile"),
pch=c("-", "_", "_", "_", "-"),
pt.lwd=0.5, pt.cex=c(1, 1, 2, 1, 1), xjust=1)

Sepal length variance per regression tree leaf

关于r - 如何从回归树 rpart 对象生成预测区间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29131254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com