本文介绍了二叉决策树(CART)的分裂和根节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在回归树中找到分裂和根节点,我从多个向量制作了一个回归树,现在我必须提取多个向量的rpart的根节点.文件包含多个向量的数值A,B,C,D,E,F,G,H 例如.一个向量包含 4,3,6,7,2,4,5,...等类似的其他 B,C,D,E,F,G,H .so 想要提取 F(在我的例子中是一个根节点)作为这个输入的输出,并在创建一棵树之后.谢谢.抱歉,无法放置任何图像:(

How to find a split and root node in a regression tree, I made a regression tree from multiple vectors now I have to extract root node of rpart of multiple vectors.file contains numeric value of multiple vectors A,B,C,D,E,F,G,H ex. A vector contains 4,3,6,7,2,4,5,...and so on similarly others B,C,D,E,F,G,H .so want to extract F (which is a root node in my case) as an output from this input an after creating a tree .thank you.sorry unable to put any image :(

这是我到目前为止所做的

Here's what I've done so far

log_data <- read.csv(file="C:\\Users\\AASHU\\Desktop\\CART\\syn.csv",
                      header=T, as.is=T)
library(rpart)

fit <- rpart(A ~ B+C+D+E+F+G+H, log_data)
# plot(fit)
plot(fit, compress=TRUE, branch=0)
text(fit, xpd = NA, cex = 0.7)

summary(fit)
Call:
rpart(formula = A ~ B + C + D + E + F + G + H, data = log_data)
n=52 (1 observation deleted due to missingness)

          CP nsplit rel error   xerror      xstd
1 0.09798662      0 1.0000000 1.065250 0.1888568

2 0.09347624      1 0.9020134 1.198999 0.1842667

3 0.03632980      2 0.8085371 1.154558 0.1859743

4 0.02297130      3 0.7722073 1.254874 0.2029423

5 0.01000000      4 0.7492360 1.274024 0.2118272

Node number 1: 52 observations,    complexity param=0.09798662

 mean=4.403846, MSE=1.509985

 left son=2 (7 obs) right son=3 (45 obs)

 Primary splits:

F < 5.5 to the right, improve=0.09798662, (0 missing)

…………现在我必须从拟合(回归树)和它的分裂中提取根节点 F(F>=5.5),有人可以帮我吗?.

...........Now I have to extract root node F(F>=5.5) from fit (regression tree) and its split,can anyone help me?.

推荐答案

找到那棵树的标签,以便我们可以提取任何向量

find the lables of that tree so that we can extract any of the vector

当根节点为字符时(例如-A)

when the root node is character(ex.-A)

nodes<-labels(fit, digits=4, minlength=1L, pretty, collapse=TRUE)
root<-substr(nodes[2], 1, 1)

路径我们可以提取一棵树的根节点,下面的一个最好通过它的第二个分裂来提取根节点名称,它只是一个根节点.

from the path we can extract the root node of a tree,below one is best to extract root node name by going through its second split which is nothing but an root node.

nodes<-labels(fit, digits=4, minlength=1L, pretty, collapse=TRUE)
path<-path.rpart(fit, node_no, pretty=0, print.it=FALSE)
path[[2]][1]

这篇关于二叉决策树(CART)的分裂和根节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:14