show volume in each node using ctree , plot in R

﹥>﹥吖頭↗ 提交于 2019-12-11 01:35:57

问题


can any one please show me how to add volume in each of the nodes , instead of the final node volume

t <- ctree(is_return ~ a + b + c)    
plot(t, type="simple")

and my tree would look like

how can I modified that plot where it would show N= on every circle nodes , not only the black or the final node.

Thanks


回答1:


The idea is to specify a panel functions for plotting inner nodes.

I generate some data, and the tree

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)

The custom inner plot function. I draw a circle where i write the some of weights.

innerWeights <- function(node){
  grid.circle(gp = gpar(fill = "White", col = 1))
  mainlab <- paste( node$psplit$variableName, "\n(n = ")
  mainlab <- paste(mainlab, sum(node$weights),")" , sep = "")
  grid.text(mainlab,gp = gpar(col='red'))
}

I plot the tree

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

PS: the results depends on a random generated data, so you will not probably get the same plot.




回答2:


When exporting the decision tree, change the dimensions of the image. for a decision tree with 200 terminal nodes the width should be about 30.000.



来源:https://stackoverflow.com/questions/13772715/show-volume-in-each-node-using-ctree-plot-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!