Multidimensional distribution of GBM, how to use pred () to get the predicted class?

I use the polynomial 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 the appearance of each class. How to recover probabilities? Thanks.

+8
r categorical-data prediction multinomial gbm
source share
2 answers

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

+1
source share

predict.gbm(..., type='response') does not apply to polynomials or even to any distribution other than bernoulli or poisson.

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

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

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

+9
source share

All Articles