Reputation:
here is part of my code below for an assignment I am working on this semester:
fit2=glm(card~reports+income+age+owner+dependents+months+share, data=new_credit2, family="binomial")
summary(fit2)
####Part G####
pred_prob=predict(fit2,type="response")
head(pred_prob)
length(pred_prob)
# The contrasts() function indicates that R has created a dummy variable with a 1 for =Yes
contrasts(card)
# The following command creates a vector of 1,319 No elements
glm.pred=rep("No",1319)
#The following command transforms all the elements with predicted probabilities of acceptance
greater than 0.5 from No to Yes
glm.pred[pred_prob>.5]="Yes"
head(glm.pred)
head(card)
#table() produces a confusion matrix to determine how many observations were correctly or
incorrectly classified
table(glm.pred,card)
# mean(): computes fraction of individual for which the prediction was correct
mean(glm.pred==card)
When I run this I get a matrix that looks like this:
card
glm.pred no yes
No 86 232
Yes 210 791
Yet, when I run the mean() function to try to get the fraction of correct predictions, I get a result of 0. I am unsure why this is occurring, and was hoping someone could lead me in the right direction.
Thanks everyone
Upvotes: 0
Views: 330
Reputation: 6954
If this is really your output, notice the different spelling of Yes - yes and No - no. Cheers
Upvotes: 1