gpt4 book ai didi

r - 如何获取所有终端节点 - r 中的权重和响应预测 'ctree'

转载 作者:行者123 更新时间:2023-12-01 12:48:27 26 4
gpt4 key购买 nike

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

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

enter image description here

——
以下是我迄今为止获得的重量

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

谢谢

最佳答案

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

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

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

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

enter image description here

关于r - 如何获取所有终端节点 - r 中的权重和响应预测 'ctree',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13959431/

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