1

我认为在我研究解决这个问题的过程中,我非常接近。我正在为C5.0 包寻找类似的东西。

SO答案中提供的方法适用于party对象。但是 C5.0 包不支持as.party. 在我进一步的研究中,我发现这个评论说 C5.0 包的维护者已经编写了这个函数,但没有导出它。

我认为这应该可以工作,但不幸的是,建议的函数C50:::as.party.C5.0(mod1)会引发错误:

error in as.data.frame.default(x[[i]], optional = TRUE) : 
    cannot coerce class ""function"" to a data.frame

任何解决此错误的建议表示赞赏。让我们使用以下示例:

library(C50)
p = iris[1:4]
t = factor(iris$Species)
model = C50::C5.0(p,t)
#summary(model)

modParty = C50:::as.party.C5.0(model)
4

1 回答 1

3

当使用默认方法而C5.0()不是公式方法时,似乎会出现问题。如果您使用后者,则as.party()转换成功,您可以为此应用所有方法:

model <- C5.0(Species ~ ., data = iris)
modParty <- C50:::as.party.C5.0(model)
modParty
## Model formula:
## Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width
## 
## Fitted party:
## [1] root
## |   [2] Petal.Length <= 1.9: setosa (n = 50, err = 0.0%)
## |   [3] Petal.Length > 1.9
## |   |   [4] Petal.Width <= 1.7
## |   |   |   [5] Petal.Length <= 4.9: versicolor (n = 48, err = 2.1%)
## |   |   |   [6] Petal.Length > 4.9: virginica (n = 6, err = 33.3%)
## |   |   [7] Petal.Width > 1.7: virginica (n = 46, err = 2.2%)
## 
## Number of inner nodes:    3
## Number of terminal nodes: 4

然后选择您链接的其他讨论中的预测路径:

pathpred(modParty)[c(1, 51, 101), ]
##       response prob.setosa prob.versicolor prob.virginica
## 1       setosa  1.00000000      0.00000000     0.00000000
## 51  versicolor  0.00000000      0.97916667     0.02083333
## 101  virginica  0.00000000      0.02173913     0.97826087
##                                                              rule
## 1                                             Petal.Length <= 1.9
## 51  Petal.Length > 1.9 & Petal.Width <= 1.7 & Petal.Length <= 4.9
## 101                        Petal.Length > 1.9 & Petal.Width > 1.7

我不确定为什么该方法不适用于默认界面。但可能设置所需的模型框架更加困难。不过,您可能会考虑向C50维护者询问这一点。

于 2016-05-23T14:28:48.883 回答