【发布时间】:2015-12-28 10:56:49
【问题描述】:
我正在尝试查找增强模型的准确性。我的代码是这样的:
wine.boost = gbm(as.factor(wine) ~ alcohol+hue, data = italiantrain,
distribution = "multinomial", n.trees = 5000 , interaction.depth = 2)
wine.boost.testpredict = predict(wine.boost, newdata=italiantest,
n.trees =5000, type = "response")
confusionMatrix(wine.boost.testpredict, italiantrain$wine)
当我尝试这个时,我收到以下错误:
Error in confusionMatrix.default(wine.boost.trainpredict, italiantest$wine):
the data cannot have more levels than the reference
我不确定要纠正什么或我做错了什么。有什么建议吗?
【问题讨论】:
-
这个错误看起来很简单,你能至少分享一下你的数据集的结构吗?
-
'data.frame':178 obs。 8 个变量:$ 代码:因子 w/178 个级别“ERA0174”,“ERA0176”,..:120 123 126 129 132 135 138 141 144 147 ... $ wine:因子 w/3 个级别“Barbera”,“Barolo” ",..: 2 2 2 2 2 2 2 2 2 2 ... $酒精: num 14.2 13.2 13.2 14.4 13.2 ... $ 糖: num 24.8 26.3 26.3 25.9 26 ... $ 酸度: num 73.1 72.8 68.5 74.9 83.5 ... $ ph:num 3.38 3.3 3.48 3.48 3.42 3.39 3.42 3.54 3.3 3.27 ... $ color:num 5.64 4.38 5.68 7.8 4.32 6.75 5.25 5.05 5.2 7.22 ... $ hue:num 1.04 1.05 1.03 0.86 1.04 1.05 1.02 1.06 1.08 1.01 ...
-
拥有数据会很有帮助。该消息似乎在说预测向量和参考向量中的因子级别数量存在差异。您可以使用命令 nlevels 进行检查。
标签: r r-caret multinomial gbm