我认为在我解决这个问题的研究中,我走得很近。我正在为C5.0软件包寻找类似这的东西。
所以应答中提供的方法适用于一个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)发布于 2016-05-23 14:28:48
这个问题似乎发生在使用默认的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维护人员。
https://stackoverflow.com/questions/37393329
复制相似问题