This question already has an answer here:
My response is a categorical variable (some alphabets), so I used distribution='multinomial' when making the model, and now I want to predict the response and obtain the output in terms of these alphabets, instead of matrix of probabilities.
However in predict(model, newdata, type='response')
, it gives probabilities, same as the result of type='link'
.
Is there a way to obtain categorical outputs?
BST = gbm(V1~.,data=training,distribution='multinomial',n.trees=2000,interaction.depth=4,cv.folds=5,shrinkage=0.005)
predBST = predict(BST,newdata=test,type='response')
In
predict.gbm
documentation, it is mentioned:What you should do, as Dominic suggests, is to pick the response with the highest probability from the resulting
predBST
matrix, by doingapply(.., 1, which.max)
on the vector output from prediction. Here is a code sample with theiris
dataset: