Logistic回归混淆矩阵

问题描述 投票:0回答:1

这是我本学期正在做的作业的下面代码的一部分:

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)

当我运行它时,我得到一个看起来像这样的矩阵:

         card
glm.pred  no yes
     No   86 232
     Yes 210 791

但是,当我运行mean()函数尝试获得正确预测的分数时,得到的结果为0。我不确定为什么会这样,并希望有人可以将我引向正确的方向。] >

谢谢大家

这是我在本学期正在处理的作业的以下代码的一部分:fit2 = glm(card〜reports + income + age + age + owner + depends + months + share,data = new_credit2,family =“ binomial”)摘要(fit2)#### ...

r logistic-regression confusion-matrix
1个回答
0
投票

如果这确实是您的输出,请注意是-是和否-否的不同拼写。干杯

© www.soinside.com 2019 - 2024. All rights reserved.