我试图弄清楚,但不知道当某些预测变量中存在缺失值时会发生什么,我们必须使用随机森林解决回归问题。代理拆分来处理它的含义是什么?
如果可以显示丢失数据部分中算法工作的快照,那将是很好的。
我试图弄清楚,但不知道当某些预测变量中存在缺失值时会发生什么,我们必须使用随机森林解决回归问题。代理拆分来处理它的含义是什么?
如果可以显示丢失数据部分中算法工作的快照,那将是很好的。
本网站的其他地方引用了代理拆分,但我找不到它们的解释。例如:
我使用rpart 文档和这些讲义来举例说明代理拆分。rpart
我使用in构建了一个示例R
:
tmp_df <-
data.frame(Y = as.factor(c(1, 1, 1, 1, 1, 0, 0, 0, 0, 0)),
weight = 10:1,
height = c(10:7, 5, 6, 4:1))
tmp_df$weight[3] <- NA
这会生成以下数据框:
Y weight height
1 1 10 10
2 1 9 9
3 1 8 8
4 1 7 7
5 1 6 5
6 0 5 6
7 0 NA 4
8 0 3 3
9 0 2 2
10 0 1 1
通过构造的意图很清楚,如果变量没有缺失值,则截点weight > 5.5
为分类响应提供了完美的分割。Y
weight
现在,忽略缺失值的算法只会丢弃第 7 行,但仍会获得等价于 的拆分weight > 5.5
。该包rpart
不这样做,而是计算高度变量的代理拆分height > 3.5
。
这背后的想法如下:Weight
显然是拆分的最佳变量。但是,当Weight
缺失时,使用 的分割Height
是对使用 获得的分割的良好近似Weight
。
让我们拟合两个模型来演示这一点,首先,tm_0
一个没有代理的普通树模型,tm
一个使用默认代理行为的树模型rpart
:
tm_0 <- rpart(Y ~ weight + height, data = tmp_df,
control = rpart.control(minsplit = 1,
minbucket=1,
cp=0,
maxdepth = 1,
usesurrogate = 0))
tm <- rpart(Y ~ weight + height, data = tmp_df,
control = rpart.control(minsplit =1,
minbucket=1,
cp=0,
maxdepth = 1))
我们看到分裂就像我描述的那样,来自summary(tm)
:
Primary splits:
weight < 5.5 to the left, improve=4.444444, (1 missing)
height < 4.5 to the left, improve=3.333333, (0 missing)
Surrogate splits:
height < 3.5 to the left, agree=0.889, adj=0.75, (1 split)
现在,使用以下新数据比较这两个模型的预测:
tmp_new_df <- data.frame(weight = c(rep(NA_real_, 4), 3:6), height = rep(3:6, 2))
> tmp_new_df
weight height
1 NA 3
2 NA 4
3 NA 5
4 NA 6
5 3 3
6 4 4
7 5 5
8 6 6
对比predict(tm_0, newdata = tmp_new_df)
(第一列是在类的概率0
):
0 1
1 0.5 0.5
2 0.5 0.5
3 0.5 0.5
4 0.5 0.5
5 1.0 0.0
6 1.0 0.0
7 1.0 0.0
8 0.0 1.0
至predict(tm, newdata = tmp_new_df)
:
0 1
1 1.0000000 0.0000000
2 0.1666667 0.8333333
3 0.1666667 0.8333333
4 0.1666667 0.8333333
5 1.0000000 0.0000000
6 1.0000000 0.0000000
7 1.0000000 0.0000000
8 0.1666667 0.8333333
在前四行中,由于weight
存在缺失值,因此决策树tm_0
无法使用对 的拆分进行预测weight
,因此返回根节点处的类成员比率。相反,tm
使用代理拆分的树能够使用该height
变量对这些行进行更准确的预测。但是,请注意后四行的差异。由于预测变量中缺失值的观察结果如何在终端节点中聚合,具有代理分裂的树无法给出“完美”的预测。(有关详细信息,请参阅 rpart 的文档)。