当使用默认方法而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
维护者询问这一点。