我想用我的訓練數據來計算兩個混淆矩陣用於我的邏輯迴歸邏輯迴歸和我的測試數據:混淆矩陣爲R中
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
爲什麼這是一個錯誤?我怎樣才能解決這個問題?謝謝!
您需要將測試數據集傳遞給預測功能,否則將對列車數據集進行預測。即預測(logitMod,newdata = test,type =「response」) – user20650
Thx它的工作原理! –