将“C50 型号”转换为“rpart”型号

sta*_*oob 5 tree r data-visualization decision-tree rpart

有没有办法使用rpart.plot库来绘制不属于的对象rpart(用于制作决策树)?

例如,以下是正在运行的经典rpartrpart.plot

#load libraries
    library(rpart)
    library(rpart.plot)

#load data
    data(iris)

#fit rpart model (i.e. decision tree)
    r = rpart(Species ~., data=iris)

#plot model
    rpart.plot(r)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

问题:我正在研究一个多类分类问题(如上面的示例 - 我只是用著名的“iris 数据集”说明了这一点),其中“rpart”运行时间太长(我等了 10 个小时,“rpart”代码仍然没有运行)。

然而,我在 R 中发现了另一个名为“c50”的库,它能够立即创建类似的模型:

#load library 
library(C50)

#run same model
tree_mod <- C5.0(x = iris[, -5], y = iris$Species, rules = TRUE)

#view model
summary(tree_mod)

plot(tree_mod)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

问题:是否可以将“rpart.plot”库与“C50”库中的对象一起使用?

例如:

#my attempt
rpart.plot(tree_mod)

Error in rpart.plot(tree_mod) : Not an rpart object
Run Code Online (Sandbox Code Playgroud)

我的想法: 可以使用“C50”库提取不同的规则:

summary(tree_mod)

Rule 1: (50, lift 2.9)
    Petal.Length <= 1.9
    ->  class setosa  [0.981]

Rule 2: (48/1, lift 2.9)
    Petal.Length > 1.9
    Petal.Length <= 4.9
    Petal.Width <= 1.7
    ->  class versicolor  [0.960]

Rule 3: (46/1, lift 2.9)
    Petal.Width > 1.7
    ->  class virginica  [0.958]

Rule 4: (46/2, lift 2.8)
    Petal.Length > 4.9
    ->  class virginica  [0.938]
Run Code Online (Sandbox Code Playgroud)

类似的规则也可以从“rpart”库中提取:

 rpart.rules(r)

    Species  seto vers virg                                               
     setosa [1.00  .00  .00] when Petal.Length <  2.5                     
 versicolor [ .00  .91  .09] when Petal.Length >= 2.5 & Petal.Width <  1.8
  virginica [ .00  .02  .98] when Petal.Length >= 2.5 & Petal.Width >= 1.8
Run Code Online (Sandbox Code Playgroud)

C50是否有可能以某种方式从库中“重新格式化规则”,使它们与 兼容rpart.plot