如何获得所有终端节点-重量和重量R中的响应预测'ctree' [英] how to get all terminal nodes - weight & response prediction 'ctree' in r

查看:79
本文介绍了如何获得所有终端节点-重量和重量R中的响应预测'ctree'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我可以用来列出所有终端节点的权重的方法:但是如何添加一些代码以获取响应预测以及每个终端节点ID的权重:

Here's what I can use to list weight for all terminal nodes : but how can I add some code to get response prediction as well as weight by each terminal node ID :

说我希望我的输出看起来像这样

say I want my output to look like this

-
这是到目前为止我能得到的重量

-- Here below is what I have so far to get the weight

nodes(airct, unique(where(airct))) 

谢谢

推荐答案

二叉树是一个很大的S4对象,因此有时很难提取数据。

The Binary tree is a big S4 object, so sometimes it is difficult to extract the data.

但是BinaryTree对象的plot方法具有绘制终端节点的形式为function(node)的可选面板函数。因此,当绘制时,您可以获得有关此节点的所有信息。

But the plot method for BinaryTree object, hase an optional panel function of the form function(node) plotting the terminal nodes. So when you plot you can get all the informations about this node.

在这里,我使用plot函数提取信息,甚至更好地使用 gridExtra 并打包以将终端节点的形式更改为表格

here I use the plot function, to extract the information and even better I usee the gridExtra and package to change the form of the terminal node as a table

library(party)
library(gridExtra)
set.seed(100)
lls <- data.frame(N = gl(3, 50, labels = c("A", "B", "C")), 
                  a = rnorm(150) + rep(c(1, 0,150)),
                  b = runif(150))
pond= sample(1:5,150,replace=TRUE)
tt <- ctree(formula=N~a+b, data=lls,weights = pond)
output.df <- data.frame()
innerWeights <- function(node){

 dat <- data.frame (x=node$nodeID,
                    y=sum(node$weights),
                    z=paste(round(node$prediction,2),collapse='  '))
  grid.table(dat,
             cols = c('ID','Weights','Prediction'),
             h.even.alpha=1, 
             h.odd.alpha=1,  
             v.even.alpha=0.5, 
             v.odd.alpha=1)
   output.df <<- rbind(output.df,dat)  # note the use of <<-

}

plot(tt, type='simple', terminal_panel = innerWeights)


data
  ID Weights       Prediction
1  4      24  0.42  0.5  0.08
2  5      17 0.06  0.24  0.71
3  6      24    0.08  0  0.92
4  7     388 0.37  0.37  0.26

这篇关于如何获得所有终端节点-重量和重量R中的响应预测'ctree'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆