I tried computing confusion-matrix for my glm model but I keep getting:
Error:
dataandreferenceshould be factors with the same levels.
Below is my model:
model3 <- glm(winner ~ srs.1 + srs.2, data = train_set, family = binomial)
confusionMatrix(table(predict(model3, newdata=test_set, type="response")) >= 0.5,
train_set$winner == 1)
winner variable contains team1 and team2.srs.1 and srs.2 are numerical values.
What is my problem here?
predict()function is working as expected. If not, you need to ensure that the factor levels intest_setforsrs.1andsrs.2are the same (or are a subset of) the factor levels intrain_setfor the same variables. As an example, if your testing data has variablegenderwith factor levels "male" and "female", you can't have a factor level of "other" in the testing data. - DanY