【问题标题】:Logistic regression confusion matrix逻辑回归混淆矩阵
【发布时间】:2023-04-05 13:09:02
【问题描述】:

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

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。我不确定为什么会发生这种情况,并希望有人能引导我朝着正确的方向前进。

谢谢大家

【问题讨论】:

    标签: r logistic-regression confusion-matrix


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-05-26
      • 2020-07-08
      • 2021-11-30
      • 2021-09-03
      • 2018-07-09
      • 2018-10-31
      • 2021-03-15
      • 2018-04-20
      • 2018-11-19
      相关资源
      最近更新 更多