获得增强的多项模型的准确性

时间:2015-09-30 15:15:52

标签: r r-caret multinomial gbm

我试图找到提升模型的准确性。我的代码是这样的:

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

我不确定要纠正什么或者我做错了什么。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

熟悉数据的最佳方法是不要看它:

> iris.boost = gbm(Species ~ ., data = iris,
+                  distribution = "multinomial", n.trees = 5000 , interaction.depth = 2)
> 
> iris.boost.testpredict = predict(iris.boost, newdata=iris[1:3, 1:4], 
+                                  n.trees =5000, type = "response")
> iris.boost.testpredict
, , 5000

        setosa   versicolor    virginica
[1,] 0.9987619 0.0011808413 5.722106e-05
[2,] 0.9994021 0.0004801001 1.177551e-04
[3,] 0.9993529 0.0005547632 9.236662e-05

您必须将基本gbm输出转换为系数(或使用train,它会为您执行此操作)。