Chapter 4: Classification
We generally try to find the probabilities that a given observation belongs to a class .
Pitfalls of Linear Regression
- We can use linear regression to encode variables that have binary encodings (or just 2 levels). We can use linear regression to encode variables that have some inherent ordering or equal relative distance. Beyond these restrictions, however, it's difficult to use linear regression.
- Linear regression produces a line, which can produce negative output or outputs greater than 1 for some values. This violates probabilities being on [0,1].
Linear regression models predicted output given regressors. Logistic Regression models probability that the output is within a class given regressors.
Let the odds of an event be defined as .
Let . We want to be able to map to some linear combinations of regressors. Let , where is the linear combination of regressors.
Note that . Notice that this function now has a range restricted to [0,1]. Let
Notice that , a unit increase in yields a increase in the log-odds.
We estimate logistic coefficients by seeking estimates for and such that yields close to 1 for observations of class 1 and close to 0 for observations of class 0. We find these coefficients by maximizing the likelihood function:
We can measure accuracy of coefficient estimates by computing their standard errors, finding their z-statistics, and then finding their associated p-values. Large values for z-statistics indicates evidence against .
Multiple Logistic Regression
Now and thus
Keep in mind that we are still restricting each to be indicator variables.
It's possible that we now find confounding between different variables in the multiple logistic regression setting.
Linear Discriminant Analysis
- Assume that all observations from a class follow a normal distribution.
- Shared variance of distribution of observations within each of classes.
Note that the density function in one dimension is
We let be the proportion of training data points that lie within class . In other words, is the probability that a randomly selected observation lies within the class .
Remember that Baye's theorem states that . From this, we see that
Note that if then
Thus we can use the following linear equation to classify observations based on whether or not for some observation and two discriminant functions and .
However, in order to find estimates for the discriminant functions, we need to find , , . We can use
- where is the number of observations and is the number of observations within a class .
We let the decision boundary be the value for which . Thus we will classify in class 1 for values of for which . In general, we would like the LDA decision boundary be as close to the Bayes Decision boundary as possible, since the Bayes Decision boundary is the theoretically optimal decision boundary.
Linear Discriminant Analysis for
Assume that is drawn from a multivariate Gaussian distribution with a class-specific mean vector and common covariance matrix. We say that , which means that has a multivariate Gaussian distribution with a mean vector and a covariance matrix . Here's a few quick notes
- Covariance extends idea of variance to multiple dimensions
- is a matrix where cell is the covariance between predictors and . Remember that
- Each cell along the diagonal of covariance matrix represents the covariance of a predictor with itself, which is nothing but the variance of since
- Let by centering the distributions of X and Y. In this case, .
Multivariate Gaussian density:
LDA for assumes that observations from each class are drawn from . is a class-specific mean vector. is a covariance matrix common to all classes (assumption).
Notice that this is linear since the only term with any is . This is a key observation when examining the differences between LDA and QDA.
Note: In LDA where , we have Bayes decision boundaries.
Interpereting confusion matrices in context of LDA performance on
credit data set
The credit data set contains information about individuals including whether or not those individuals defaulted on their loans
In a confusion matrix, we can see the true and false positives and negatives that result from a model. The general form of a confusion matrix is:
For the default status in the credit card data set that results from running LDA, we obtain the following confusion matrix:
||True Default status
We see that only 3.33% of individuals in the training sample defaulted. This means that even a null classifier that predicts every individual never defaults will have an error rate of 3.33%. LDA on this training set gives us an error rate of 2.75%, which is very close to the error rate of the null classifier. We can also see that of the 333 individuals that defaulted, LDA missed 252 of them (that's 75.7%!).
An important note to make here is that vanilla LDA will always minimize the total error rate by approximating the Bayes error rate (which stems from trying to minimize the total number of misclassifications). In this case, that's not the best idea. We might actually care more about catching defaulters than incorrectly labelling people who didn't default as defaulters.
We can alleviate this issue by changing the threshold for classifications. For LDA, if for a two-class setting, then we classify the observation into class . We can reduce this threshold to assign more observations to class , though some of these observations might have probabilities slightly lower than . It's important to note that the Bayes classifier uses as its threshold since this threshold minimizes the total error rate in a two-class setting. Specifically in the context of predicting defaulters on credit card loans, we can change the condition satisfied for predicting
default = yes from to .
After reducing the threshold away from the threshold used by the Bayes classifier, our total error rate has to increase. However, the error rate we cared about (misclassifications of defaulters as non-defaulters) should have decreased. This is exactly what happened. LDA now misclassifies only 41% of defaulters as non-defaulters but the overall error rate increases to 3.73% (since some non-defaulters now get classified as defaulters).
Check out this ROC Curve. It has False Positive Rate on the x-axis and True Positive Rate on the y-axis. The ROC Curve is generated with respect to the performance of a single model tested at various thresholds.
Some key observations about the curve. Let there be class for whatever class is positive.
- At the point (0,0), our threshold is 1. This means that an observations needs to have a probability of 1 to be classified to . Since this will never happen, no observation is ever classified to and thus our True and False positive rates are 0.
- At the point (1,1), our threshold is 0. This means that every observation gets classified to . Intuitively, this implies that all observations that are not in are classified to (which makes the False Positive Rate skyrocket to 1). Similarly, all observations that are truly in are classified to (which makes the True Positive Rate also equal to 1).
- The optimal classifier performs at (0,1). This means that we have 0 false positive readings and only true positive readings. Thus, ideally, we want this curve to hug the top left corner.
- Since we want the curve to hug the top left corner, models with ROC curves of higher area (under the curve) are considered "good."
- The dashed line in the middle is the line of the model that randomly assigns an observation to .
- The worst models classify observations in direct opposition to good models. In other words, if a good model classifies to , a bad model would deliberately classify the same observation to another class. These models have areas lower than the area under the dashed line.
Quadratic Discriminant Analysis
QDA is pretty much the same thing as LDA but we relax a critical assumption made during LDA. We now allow individual classes to have their own covariance matrices. In other words, instead of for all classes and , we now let each class retain its own covariance matrix.
The discriminant function (which is really long to type - just look at section 4.4.4 for the equation) now has quadratic and cross terms. Why? When we apply the log transformation to the Gaussian function that models our predictors, we end up with the term in the resulting discriminant function. This key observation is what makes our decision boundaries quadratic, hend the Q in QDA.
A few important things about QDA:
- Uses class-specific covariance matrices in the discriminant functions
- Has an error rate LDA model. This is because LDA does not include the quadratic terms or the cross-terms found in QDA.
- QDA results in an elliptical Bayesian decision boundary.
- QDA generally has higher variance than LDA since it is more flexible but has lower bias.
This is a model that works surprisingly well when is large.
Key assumption: All predictors are independent and uncorrellated with eachother. In other words, all are diagonal matrices. The implication of this is that Naive Bayes assumes that all predictors are uncorrellated with eachother. This might seem crazy to do; here's an intuitive reason for why it works well for large p:
- Generally, correllation between predictors changes the shapes and orientations of Gaussian surfaces. However, the maximum posterior probability may not be highly dependent on the shape and orientations of the surfaces. We care about the maximum posterior probability since the class for which its associated posterior probability is largest for a given observation is the class we assign the observation to. Anyway, making this assumption allows for much easier computation (since p is large) and produces similar results for the maximum posterior probability. Specifically, this assumption allows us to compute covariances for the diagonal matrix as opposed to covariances.
Since we've assumed that the predictors are uncorrellated, we know that is independent of where and are individual predictors in a predictor vector and and are realizations of their respective predictors. Remember that if events A and B are independent, then . Thus, .
Finally, we find that the discriminant function follows the form:
Real Quick: LDA vs Logistic
- The log-odds in both LDA and logistic is linear
- In logistic regression, estimate the parameters by maximizing the likelihood function
- In LDA, we estimate the parameters by using estimates for , , and
- For an observation that truly belongs to calss , both models strive to make the probability that belongs to the maximum. In other words, both models strive to correctly maximize the posterior probabilities.
- Logistic regression assumes that is sigmoidal. LDA assumes that is normal.