문제

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.086328 -4.738346 -8.492738 -5.980720 -4.351102 -4.738044 -3.220387 -4.732654

but I want to get the probability of each class occurring. How do I recover the probabilities? Thank You.

도움이 되었습니까?

해결책 2

Take a look at ?predict.gbm, you'll see that there is a "type" parameter to the function. Try out predict(<gbm object>, <new data>, type="response").

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top