【发布时间】:2018-02-12 04:17:24
【问题描述】:
我想使用我的训练数据和测试数据为我的逻辑回归计算两个混淆矩阵:
logitMod <- glm(LoanStatus_B ~ ., data=train, family=binomial(link="logit"))
我将预测概率的阈值设置为 0.5:
confusionMatrix(table(predict(logitMod, type="response") >= 0.5,
train$LoanStatus_B == 1))
下面的代码非常适合我的训练集。 但是,当我使用测试集时:
confusionMatrix(table(predict(logitMod, type="response") >= 0.5,
test$LoanStatus_B == 1))
它给了我一个错误
Error in table(predict(logitMod, type = "response") >= 0.5, test$LoanStatus_B == : all arguments must have the same length
这是为什么?我怎样才能解决这个问题?谢谢!
【问题讨论】:
-
你需要将测试数据集传递给预测函数,否则它将在训练数据集上进行预测。即
predict(logitMod, newdata=test, type="response") -
谢谢它的工作原理!..
标签: r validation logistic-regression confusion-matrix