-1

我已经使用ctree()from package构建了一个回归树party。我的模型的结果有许多节点,其中包含相等概率的因变量(例如:A 类 = 0.33,B 类 = 0.33,C 类 = 0.33)。我想从模型中取出这些节点。该包tree有一个snip.tree()命令,我们可以在其中指定要从模型中删除的节点号。该命令不识别使用ctree(). 请让我知道是否有办法从使用构建的回归树中删除某些节点ctree()

我使用了以下模型:

rv.mod1 <- ctree(ldclas ~ L2 + L3 + L4 + L5 + L6 + ele + ndvi + nd_var + nd_ps, data = rv, controls = ctree_control(minsplit = 0, minbucket = 0))
pr.rv.mod1 <- snip.tree(rv.mod1, nodes = nn2.rv.mod1$nodes)

nn2.rv.mod1$nodes 是一个向量,其中包含要从 rv.mod1 模型中删除的节点。但是我收到一个错误:

Error in snip.tree(rv.mod1, nodes = nn2.rv.mod1$nodes) : 
  not legitimate tree
4

1 回答 1

1

weights我认为没有直接的方法可以做到这一点,但我会使用ctree.

让我们从一个可重现的例子开始

library(party)
irisct <- ctree(Species ~ .,data = iris)
plot(irisct)

在此处输入图像描述

现在,假设您想摆脱节点号 5。您可以执行以下操作

NewWeigths <- rep(1, dim(iris)[1]) # Setting a weights vector which will be passed into the `weights` attribute in `ctree`
Node <- 5 # Selecting node #5
n <- nodes(irisct, Node)[[1]] # Retrieving the weights of that node
NewWeigths[which(as.logical(n$weights))] <- 0 # Setting these weigths to zero, so `ctree` will disregard them
irisct2 <- ctree(Species ~ .,data = iris, weights = NewWeigths) # creating the new tree with new weights
plot(irisct2)

在此处输入图像描述

请注意节点 2、6 和 7(现在它们被命名为 2、4 和 5,因为我们拆分较少)如何保持完全相同的分布和拆分条件。

我没有为所有节点测试它,但它似乎工作得相当好

于 2014-05-08T19:31:51.350 回答