# What is misclassification rate? How do we calculate it?

I'm doing logistic regression on Boston data with a column high.medv (yes/no) which indicates if the median house pricing given by column medv is either more than 25 or not.

Below is my code for logistic regression.

  train_boston_new = train_boston
train_boston_new$high.medv <- NA train_boston_new$high.medv[train_boston_new$medv <= 25] <- "no" train_boston_new$high.medv[train_boston_new$medv > 25] <- "yes" head(train_boston_new) train_boston_new.glm <- glm(high.medv ~ lstat, family = binomial, data = train_boston_new)  Now I'm required to use the misclassification rate as the measure of error for the two cases: • using lstat as the predictor, and • using all predictors except high.medv and medv. I read the ISL book by Hastie, Tibshirani and did search but not clear on what misclassification rate is and how it is calculated? • Logistic regression will give you as predicted values predicted probabilities$\hat{P}$that a house has "yes" or "no" given the predictors. If you, as is standard, predict "yes" when$\hat{P}(\text{yes}>0.5|X)$(and "no" else, with$X$the predictors), you get a classification. You can then compare the classification of your model to what is actually the case. If you compare how often your model has been wrong, you get a missclassification rate. – Christoph Hanck Apr 14 '15 at 13:21 • Worth mentioning: P^(yes>0.5|X is very inadvisable to use. At least replace 0.5 with the prior class probability. – Zhubarb Apr 14 '15 at 13:29 ## 1 Answer If$\hat{y}_i$is your prediction for the$i$th observation then the misclassification rate is${1 \over n}\sum_i I(y_i \neq \hat y_i)$, i.e. it is the proportion of misclassified observations. In R you can easily calculate this by mean(y_predicted != y_actual). Note that this only applies to the case where$y$is a categorical class label and not a continuous response. As Christoph described in his comment, you don't directly get class labels from a logistic regression. You need to threshold the predicted posterior probabilities in order to get your$\hat y_i$. • I have yes/no as labels. Could you please explain what you mean by "not a continuous response' ? – caroline Apr 14 '15 at 13:27 • If you are doing a regression with a continuous response then you will almost surely find that$\forall i \ \hat y_i \neq y_i$. That's why we don't use misclassification rate for regression. We instead use$(\hat y_i - y_i)^2\$ or something of that sort to measure the disagreement between our predictions and the truth. – jld Apr 14 '15 at 13:29
• @caroline A variable with a continuous response is one which might typically be represented by a number which falls within a range. For instance x = 3.51, where x might lie between 0 and 5. Your yes/no classification is a binary or nominal ( a set of named things ) response. Regression algorithms generally give continuous responses, classifiers generally nominal responses. – image_doctor Apr 14 '15 at 14:16