GBM multinomial distribution, how to use predict() to get predicted class?

后端 未结 2 1085
暖寄归人
暖寄归人 2021-01-12 03:21

I am using the multinomial distribution from the gbm package in R. When I use the predict function, I get a series of values:

5.0         


        
2条回答
  •  一个人的身影
    2021-01-12 04:18

    predict.gbm(..., type='response') is not implemented for multinomial, or indeed any distribution other than bernoulli or poisson.

    So you have to find the most likely class (apply(.., 1, which.max) on the vector output from prediction), as desertnaut wrote:

    preds = predict(your_model, n.trees, newdata=...,type='response')
    
    pred_class <- apply(preds, 1, which.max)
    

    Just write a wrapper which accepts type='response' and returns this when it's a multinomial model.

提交回复
热议问题