Chapter 5: Classification Problems and Discriminant Analysis
In the previous chapters, we mainly discussed regression problems where the response variable \(Y\) is continuous. This chapter focuses on classification problems, where the response variable \(Y\) takes a finite set of discrete labels (e.g., \(\{0, 1\}\) or \(\{1, 2, \dots, K\}\)). We will systematically derive the two cornerstones of soft classifiers: Logistic Regression and Linear/Quadratic Discriminant Analysis (LDA/QDA), and provide the relevant mathematical derivations and property proofs rigorously.
1. Basic Setup of Classification Problems and Decision Theory
Definition 1.1 (Classifier and 0-1 Loss)
Let the training dataset be \(\mathcal{D}_{n}=\{(x_{i}, y_{i})\}_{i=1}^{n}\), where the feature vector \(x_{i} \in \mathbb{R}^p\) and the response variable \(y_{i} \in \{0, 1\}\) (or \(\{-1, +1\}\) in binary classification). The goal of a classification task is to learn a mapping function (i.e., a classifier):
Its performance is typically measured by the 0-1 loss function:
1.1 Bayes Optimal Classifier
To minimize the overall expected risk, we need to find the optimal classification rule.
Theorem 1.1 (Bayes Decision Criterion)
Under the 0-1 loss, the decision function that minimizes the expected risk \(R(f) = \mathbb{E}_{X,Y}[L(f(X), Y)]\) is the Bayes optimal classifier \(f^*(x)\), given by:
Proof: Derivation of the Optimality of the Bayes Decision
Using the law of total expectation, the expected risk can be expanded by conditioning on the feature \(X\):
To minimize the overall expectation, it suffices to minimize the conditional expectation (conditional risk) for each fixed \(X = x\):
For binary classification, the above expression can be written as:
Clearly, minimizing \(1 - P(Y = f(x) \mid X = x)\) is equivalent to maximizing \(P(Y = f(x) \mid X = x)\). Therefore, the predicted value \(f(x)\) of the classifier at point \(x\) should be the class that maximizes the conditional probability:
This completes the proof that the posterior probability maximization criterion (Bayes criterion) is optimal under the 0-1 loss.
2. Logistic Regression
Logistic regression is a parametric method that directly models the posterior conditional probability \(P(Y=1 \mid X=x)\).
Definition 2.1 (Logistic Model and Logit Transformation)
Let \(\eta(x) = P(Y = 1 \mid X = x)\). To map a linear predictor defined on \(\mathbb{R}^p\) to the probability interval \([0, 1]\), the model introduces the Logit transformation (log-odds):
By algebraic inversion, the conditional probability can be directly expressed in the Sigmoid function form:
2.1 Maximum Likelihood Estimation (MLE)
Since the response variable \(Y_i \mid x_i \sim \text{Bernoulli}(\eta(x_i))\), we can write the likelihood function for the parameter \(\theta = (\beta_0, \beta^{\top})^{\top}\). For brevity, let the augmented feature vector be \(x_i = (1, x_{i1}, \dots, x_{ip})^{\top}\).
Theorem 2.2 (Log-likelihood Function and Gradient for Logistic Regression)
The maximum likelihood estimation of the logistic regression parameters is achieved by minimizing the negative log-likelihood function (i.e., the cross-entropy loss):
Its gradient vector (first derivative) with respect to the parameter \(\theta\) is:
Proof: Detailed Calculus Derivation of the Gradient Formula
First, compute the derivative of the Sigmoid function \(\eta_i = \eta(x_i) = \frac{1}{1 + e^{-\theta^{\top}x_i}}\) with respect to \(\theta\). By the chain rule:
Next, take the partial derivative of the log-likelihood term \(L_i = y_i \ln \eta_i + (1 - y_i) \ln (1 - \eta_i)\) with respect to \(\theta\):
Substitute \(\frac{\partial \eta_i}{\partial \theta} = \eta_i (1 - \eta_i) x_i\) into the above expression:
Therefore, the gradient of the negative log-likelihood function \(\ell(\theta) = -\sum_{i=1}^n L_i\) is:
This completes the proof. Since this objective function is strictly log-concave with respect to \(\theta\), it is typically solved iteratively using the Newton-Raphson method or gradient descent in practice.
3. Generative Models: Discriminant Analysis
Unlike logistic regression, discriminant analysis belongs to the family of generative models. It first models the conditional probability density of the features within each class \(k\), \(f_k(x) = f(X=x \mid Y=k)\), and the class prior probabilities \(\pi_k = P(Y=k)\), and then uses Bayes' theorem to derive the posterior probabilities.
By Bayes' theorem, given \(X=x\), the posterior probability of belonging to class \(k\) is:
We assume that the data within each class follow a multivariate normal distribution:
3.1 Linear Discriminant Analysis (LDA)
Definition 3.1 (Basic Assumption of LDA)
Linear Discriminant Analysis (LDA) assumes that the covariance matrices of all classes are equal, i.e.:
Theorem 3.1 (Linear Discriminant Function of LDA)
Under the assumption of equal covariance matrices across classes, maximizing the Bayes posterior probability is equivalent to maximizing the following linear discriminant function \(\delta_k(x)\) in terms of \(x\):
Proof: Mathematical Derivation of the LDA Linear Discriminant Function
To maximize \(P(Y=k \mid X=x)\), since the denominator \(\sum_{l=1}^K \pi_l f_l(x)\) of Bayes' formula is the same for all classes \(k\), we only need to maximize the numerator term:
Since the logarithm function is monotonically increasing, we take the natural logarithm of the numerator term:
Substituting and expanding the multivariate normal density \(f_k(x)\) (with \(\Sigma_k = \Sigma\)):
Note that the terms \(-\frac{p}{2}\ln(2\pi) - \frac{1}{2}\ln|\Sigma|\) are constants independent of the class \(k\) and can be removed when making the maximization decision over \(k\). Expand the remaining part:
Again, note that the term \(x^{\top}\Sigma^{-1}x\) is also independent of the class \(k\) and can be ignored. After simplification and consolidation, the core part relevant to \(k\) remains:
Since the highest-order term in the unknown variable \(x\) in the above expression is linear, the decision boundary between different classes (i.e., the hyperplane where \(\delta_k(x) = \delta_l(x)\)) is geometrically a linear hyperplane. This completes the proof.
3.2 Quadratic Discriminant Analysis (QDA)
Definition 3.2 (Basic Assumption of QDA)
Quadratic Discriminant Analysis (QDA) relaxes the assumption of equal covariance matrices, allowing different classes to have their own distinct feature covariance matrices \(\Sigma_k\).
In this case, the quadratic terms and determinant terms cannot be eliminated from the log-likelihood expression. Preserving the full feature parameters, the quadratic discriminant function of QDA is expressed as:
Since the term \(x^{\top}\Sigma_k^{-1}x\) cannot be eliminated, the decision boundary between different classes will be a quadratic surface (e.g., hyperbola, ellipse, or parabola).
4. Deep Statistical Connection between Logistic Regression and LDA
If we carefully examine the log-odds of the two classes under LDA in a binary classification problem, we arrive at a striking conclusion.
Theorem 4.1 (Implicit Logit Form of LDA)
For the LDA model, the log-odds of class 1 versus class 0 given features \(x\) have an exact linear form:
where the parameters correspond as follows:
4.1 Core Difference: Conditional Likelihood vs. Full Likelihood
Although from the above it is evident that LDA and logistic regression both lead to a linear decision boundary for the posterior odds in form, their fundamental difference lies in the basis of parameter estimation and the strength of assumptions:
-
Logistic Regression (Conditional Likelihood): It only models the conditional probability \(P(Y \mid X)\) in a discriminative manner. It does not require any normality or independence assumptions about the marginal distribution of the features \(X\). Therefore, logistic regression is more robust when the feature data do not follow a normal distribution (e.g., when they include discrete dummy variables).
-
LDA (Full Likelihood): It relies on the strong generative assumption that the features jointly follow a multivariate normal distribution. When this assumption is truly satisfied, LDA can fully exploit the information in the feature space, and its parameter estimation efficiency (variance) in the limiting case is significantly better than that of logistic regression.
5. Naive Bayes Classifier
When the feature dimension \(p\) is very large, accurately estimating the full covariance matrix \(\Sigma\) in LDA or multiple \(\Sigma_k\) in QDA with limited samples suffers from the severe "curse of dimensionality" (too many parameters leading to high variance in estimates). The Naive Bayes algorithm introduces an extreme conditional independence assumption to simplify the computation.
Definition 5.1 (Naive Bayes Conditional Independence Assumption)
The Naive Bayes classifier assumes that, given the class label \(Y=k\), the individual feature variables \(X_1, X_2, \dots, X_p\) are conditionally independent of each other.
Under this assumption, the joint conditional density function can be factorized as the product of the marginal densities of each variable:
Substituting into the Bayes decision rule, the final discriminant criterion for Naive Bayes becomes:
- Algorithm Advantage: By decomposing the multi-dimensional density estimation into \(p\) independent one-dimensional density estimates \(f_{kj}(x_j)\), Naive Bayes reduces the order of magnitude of parameter estimation from \(\mathcal{O}(p^2)\) directly to \(\mathcal{O}(p)\). For continuous features, the one-dimensional density \(f_{kj}\) can be fitted by a univariate normal distribution or univariate kernel density estimation (KDE); for discrete features, simple frequency histograms are used for counting estimates.