我使用'ctree‘作为分类树(分类响应变量;New,替换)。我已经从其他可用的答案得到帮助,并迫使模型开始分裂的基础上‘年’。我有四个自变量(包括“年份”),但模型只使用了一个重要变量,因此,我也想迫使模型根据其他参数分裂成其他节点。
我得到了How to specify split in a decision tree in R programming? @Achim Zeileis的帮助
..。
带有“各方”包的决策树 图书馆(Partykit) set.seed(123) tr1<- ctree(new_ROWTS ~年份,数据=培训) tr2<- ctree(new_ROWTS ~年份+ STI_OWTS_00+capacity_per_bed+system_type,data =培训,子集=预测(tr1,type =“节点”)==2) tr3<- ctree(new_ROWTS ~年份+ STI_OWTS_00+capacity_per_bed+system_type,数据=训练,子集=预测(tr1,类型=“节点”)==3).##Extract所有三棵树的原始节点结构,修复节点id:##固定物<- function(x,startid = 1L) { id <- startid - 1L new_node <- function ){ id <- id +1L if(is.terminal (x) )返回( partynode(id,info =info_node(X)partynode(id,split = split_node(x),three = lapply(kids_node(x),new_node),new_node= surrogates_node(x),info =info_node(X)} return (new_node(x)) } no <- node_party(tr1) no $fixids <- list <-list(node_party(Tr2),startid = 2L),fixids(node_party(tr3),startid = 3L) .##set up a model:## d <- model.frame(new_ROWTS ~年份+ STI_OWTS_00+capacity_per_bed+system_type,数据=培训) tr <- party (no,data = d,fitted =data.frame)(“(拟合)”= fitted_node(no,data = d),“(响应)”= model.response(d),check.names = FALSE),术语=术语(D),) tr <- as.constparty(tr) ##Visualizing## ##This是输出:叶1(年份)分为两个节点: 19982之前和>1998年以后。节点3分裂成两个4和5## 1根2根2 V2 <= 1*3 V2 >1 V2 4 V3 <= 10.52754 *x+5 V3 > 10.52754 *
发布于 2019-05-04 03:01:05
你想要什么还不清楚。看起来,您的预测器没有足够的预测能力来包含在树中。尽管与因变量无关,但强迫分裂可能不是一个很好的解决方案。
如果您想要查看树的结构,当允许在不那么严格的符号化级别(默认为alpha = 0.05
)分割时,您可以使用类似于ctree(..., alpha = 0.8)
等的内容。详细信息请参见?ctree_control
。然而,这样一棵树的结果是否对解释和/或预测有用,则是另一个问题。
https://stackoverflow.com/questions/55976668
复制相似问题