I have 10 datasets with binary and multiclass factors, I used logistic regression with R "glm" which predicts the class probability class,prediction(formula,data,type="response")
. How can I get the predicted class instead, like other models give? For example:
df=data.frame(y=c(1,0,0,1),x1=c(1,2,3,4),x2=c(12,13,43,3))
df$y=as.factor(df$y)
testdf=data.frame(y=c(1,1,0,0),x1=c(11,16,65,8),x2=c(3,2,5,0))
testdf$y=as.factor(testdf$y)
model_glm=glm(y~.,data=df,family="binomial")
pred_glm=predict(model_glm,newdata=testdf,type="response")
this will give the probability prediction:
> pred_glm
1 2 3 4
2.220446e-16 2.220446e-16 2.220446e-16 2.220446e-16
- However I need the class prediction whether it is 0 or 1. Or the probability predictions in two columns: one for class 1 and the other for class 0?
- And how it can used when I have multi class?