I am trying to manually write code to perform a k-fold cross validation for a logistic regression model for the first time. Unfortunately I am getting stuck trying to implement the following formula from An Introduction to Statistical Learning with Applications in R:
In this setting, cross-validation works just as described earlier in this chapter, except that rather than using MSE to quantify test error, we instead use the number of misclassified observations. For instance, in the classification setting, the LOOCV error rate takes the form:
$$ CV_{(n)} = \frac{1}{n} \sum\limits_{i=1}^n Err_i $$ where $ Err_i = I(y_i \neq \hat{y_i}). $
What I'm struggling with is how to find out if a specific observation was misclassified. As I understand it, the y-hat values from a logistic regression could be any value between 0 and 1. They can essentially be interpreted as the predicted probability that an outcome = 1 based on that specific combination of predictors.
The y values can only be either 0 or 1. So it seems to me that y and y-hat will never (or almost never) be equal.
So I am left with 2 questions:
1) Do I have some conceptual misunderstanding here?
2) How can I find out how many observations my model has classified correctly?