解析决策树(来自WEKA分类器)以在R中绘图?

时间:2014-09-03 19:52:23

标签: r weka decision-tree id3 rweka

我想绘制ID3模型的结果。它似乎在WEKA和R中都没有默认的绘图模块。

是否有已经制作的代码来执行此操作? (或者,下面的树格式是否有标准名称,我可以轻松找到解析器?)

以下是一些基本代码:

# I'm getting a post from this: https://en.wikipedia.org/wiki/ID3_algorithm


## load RWeka
if(!require(RWeka)) install.packages("RWeka")
library(RWeka)
## look for a package providing id3
WPM("refresh-cache")
WPM("list-packages", "available") ## look for id3
## install package providing id3
WPM("install-package", "simpleEducationalLearningSchemes")
## load the package
WPM("load-package", "simpleEducationalLearningSchemes")
## make classifier
ID3 <- make_Weka_classifier("weka/classifiers/trees/Id3")
## test it out.

DF2 <- read.arff(system.file("arff", "contact-lenses.arff",
                             package = "RWeka"))
ID3(`contact-lenses` ~ ., data = DF2)

结果如下:

Id3


tear-prod-rate = reduced: none
tear-prod-rate = normal
|  astigmatism = no
|  |  age = young: soft
|  |  age = pre-presbyopic: soft
|  |  age = presbyopic
|  |  |  spectacle-prescrip = myope: none
|  |  |  spectacle-prescrip = hypermetrope: soft
|  astigmatism = yes
|  |  spectacle-prescrip = myope: hard
|  |  spectacle-prescrip = hypermetrope
|  |  |  age = young: hard
|  |  |  age = pre-presbyopic: none
|  |  |  age = presbyopic: none

树形结构很容易理解。关于如何解析这个的任何建议? (也许类似于答案from here?)

感谢。

1 个答案:

答案 0 :(得分:0)

可视化树的选项已经在Weka中可用了一段时间。也许你使用的是旧版本? Weka 3.6和3.7随J48一起发货。如果您只关心它的可视化,那么这个问题的答案会显示几种方式:Visualizing Weka classification tree