【发布时间】:2020-07-18 12:50:20
【问题描述】:
我使用 caret 库中的 train 函数训练了 Decision Tree 模型:
gr = expand.grid(trials = c(1, 10, 20), model = c("tree", "rules"), winnow = c(TRUE, FALSE))
dt = train(y ~ ., data = train, method = "C5.0", trControl = trainControl(method = 'cv', number = 10), tuneGrid = gr)
现在我想为最终模型绘制决策树。但是这个命令不起作用:
plot(dt$finalModel)
Error in data.frame(eval(parse(text = paste(obj$call)[xspot])), eval(parse(text = paste(obj$call)[yspot])), :
arguments imply differing number of rows: 4160, 208, 0
这里已经有人问过了:topic
建议的解决方案是使用拟合的 train 对象中的 bestTune 手动定义相关的 c5.0 模型。然后正常绘制 c5.0 模型:
c5model = C5.0(x = x, y = y, trials = dt$bestTune$trials, rules = dt$bestTune$model == "rules", control = C5.0Control(winnow = dt$bestTune$winnow))
plot(c5model)
我试图这样做。是的,它可以绘制 c5.0 模型,BUT 从 train 对象预测概率并手动重新创建 c5.0 模型 不匹配。
所以,我的问题是:是否可以从 caret::train 对象中提取最终的 c5.0 模型 并绘制此 决策树?
【问题讨论】:
标签: r decision-tree r-caret c5.0