从rpart包中的决策规则中提取信息 [英] Extracting Information from the Decision Rules in rpart package

查看:69
本文介绍了从rpart包中的决策规则中提取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从决策树中的规则中提取信息.我在R中使用rpart软件包.我在软件包中使用演示数据来解释我的要求:

I need to extract information from the rules in decision tree. I am using rpart package in R. I am using demo data in the package to explain my requirements:

data(stagec)
fit<- rpart(formula = pgstat ~ age + eet + g2 + grade + gleason + ploidy, data = stagec, method = "class", control=rpart.control(cp=0.05))
fit

打印适合的显示

n= 146 

node), split, n, loss, yval, (yprob)
      * denotes terminal node

 1) root 146 54 0 (0.6301370 0.3698630)  
   2) grade< 2.5 61  9 0 (0.8524590 0.1475410) *
   3) grade>=2.5 85 40 1 (0.4705882 0.5294118)  
     6) g2< 13.2 40 17 0 (0.5750000 0.4250000)  
      12) ploidy=diploid,tetraploid 31 11 0 (0.6451613 0.3548387) *
      13) ploidy=aneuploid 9  3 1 (0.3333333 0.6666667) *
     7) g2>=13.2 45 17 1 (0.3777778 0.6222222)  
      14) g2>=17.91 22  8 0 (0.6363636 0.3636364) *
      15) g2< 17.91 23  3 1 (0.1304348 0.8695652) *

例如我想获得以下有关第12个节点的信息

e.g. I would like to get information something like below for the 12th node

如果等级> = 2.5且g2 <13.2和(二倍体,四倍体)中的倍性预测0类的置信度为65%.任何有关此的指示将非常有帮助.

If grade>=2.5 and g2< 13.2 and ploidy in (diploid,tetraploid) then class 0 is predicted with 65% confidence. Any pointers on this would be very helpful.

谢谢

推荐答案

rpart.plot 软件包版本3.0(2018年7月)具有功能 rpart.rules 用于为树生成一组规则.例如

The rpart.plot package version 3.0 (July 2018) has a function rpart.rules for generating a set of rules for a tree. For example

library(rpart.plot)
data(stagec)
fit <- rpart(formula = pgstat ~ ., data = stagec, method = "class", control=rpart.control(cp=0.05))
rpart.rules(fit)

给予

pgstat                                                                   
  0.15 when grade <  3                                                   
  0.35 when grade >= 3 & g2 <  13       & ploidy is diploid or tetraploid
  0.36 when grade >= 3 & g2 >=       18                                  
  0.67 when grade >= 3 & g2 <  13       & ploidy is             aneuploid
  0.87 when grade >= 3 & g2 is 13 to 18 

还有

rpart.rules(fit, roundint=FALSE, clip.facs=TRUE)

给予

pgstat                                                           
  0.15 when grade <  2.5                                         
  0.35 when grade >= 2.5 & g2 <  13       & diploid or tetraploid
  0.36 when grade >= 2.5 & g2 >=       18                        
  0.67 when grade >= 2.5 & g2 <  13       & aneuploid
  0.87 when grade >= 2.5 & g2 is 13 to 18                        

有关更多示例,请参见 rpart.plot插图.

For more examples see Chapter 4 of the rpart.plot vignette.

这篇关于从rpart包中的决策规则中提取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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