3
$\begingroup$

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?

$\endgroup$
  • 2
    $\begingroup$ 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. $\endgroup$ – Christoph Hanck Apr 14 '15 at 13:21
  • 1
    $\begingroup$ Worth mentioning: P^(yes>0.5|X is very inadvisable to use. At least replace 0.5 with the prior class probability. $\endgroup$ – Zhubarb Apr 14 '15 at 13:29
4
$\begingroup$

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$.

$\endgroup$
  • $\begingroup$ I have yes/no as labels. Could you please explain what you mean by "not a continuous response' ? $\endgroup$ – caroline Apr 14 '15 at 13:27
  • $\begingroup$ 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. $\endgroup$ – jld Apr 14 '15 at 13:29
  • $\begingroup$ @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. $\endgroup$ – image_doctor Apr 14 '15 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.