R C5.0 获取每个叶节点的规则和概率

在我的研究中试图解决这个问题时,我觉得我已经非常接近答案了。我正在寻找类似于这个的内容,适用于C5.0包。

Stack Overflow上的答案中提供的方法适用于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)

回答:

问题似乎发生在使用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的维护者。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注