








Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!









Author Marc'Antonio Lopez AI & Data Analytics student at Polytechnic University of Turin
Classification in machine learning involves assigning an input data point to one of several predefined categories or classes. Generative models address this by learning the underlying process that generates the data for each class, effectively building distinct probabilistic models for each category rather than directly drawing boundaries between them.
Problem Setup in Classification:
The ultimate goal in classification is to assign a new input x_t to its most probable class given x_t. This is achieved by maximizing the posterior probability , which represents the probability of class c given the observed features x_t.
The Decision Rule: The optimal decision rule, known as the Bayes Decision Rule, dictates choosing the class that yields the highest posterior probability:
arg max Explanation: arg max means "the argument (or value) that maximizes the expression." Here, it signifies seeking the specific class label c that results in the largest value for .
Example: Object Classification Consider classifying an image x_t by the animal it contains. A generative classifier would:
The final classification would assign the image to the animal class with the highest calculated probability.
A Binary Example: Inferring Gender from Height
Let's consider a simple example: inferring a person's gender ( Male or Female ) based on their height. Histograms of male and female heights typically show two significantly overlapping bell-shaped distributions.
Using Bayes' Theorem for Classification
The posterior probability is often difficult to estimate directly. Therefore, Bayes' Theorem becomes invaluable, providing a way to express this posterior probability in terms of quantities typically easier to estimate or learn from data:
Let's break down each component:
(Class-Conditional Density / Likelihood): This term describes the probability density (for continuous features) or probability (for discrete features) of observing feature vector x given that the data belongs to class c. Generative models learn or estimate this core component for each individual class , building a model of the data's appearance within that class. (Class Prior Probability): This represents your initial belief about how likely any given data point is to belong to class c , before observing specific features x. It reflects the overall prevalence of that class in the general population or dataset.
Prior Mismatch: Implications and Compensation
A significant issue arises if the class distribution in your training dataset (the training prior ) substantially differs from the actual distribution in the real-world application (the application prior ).
Consequence of Mismatch: For instance, if training data overrepresents rare classes, the model might become biased, overestimating their likelihood in real-world scenarios where they are truly infrequent. This can lead to suboptimal performance. Compensation: If the true application prior is known, it's possible to compensate for such mismatches by adjusting the model's output probabilities. This often involves reweighting them based on the difference between training and application priors, ensuring predictions align better with real-world class frequencies.
The Gaussian Classifier: A Specific Generative Model
A particularly powerful and widely used generative classifier is the Gaussian Classifier. This model assumes that the feature data x for each class c follows a multivariate Gaussian distribution :
Here:
denotes the Gaussian (Normal) distribution. (mu-c) is the mean vector for class c. (Sigma-c) is the covariance matrix for class (^) c.
Parameters Estimated for Each Class (^) c :
To define the Gaussian distribution for each class, two main parameters must be estimated from the training data:
Where is the total number of training samples belonging to class c.
Univariate Example: Gender Inference with Gaussians
Returning to the gender inference example using height:
We would assume that male heights ( ) are drawn from a univariate Gaussian distribution:. Similarly, female heights ( ) are drawn from another univariate Gaussian distribution: .
Visually, this assumption translates to having two distinct, overlapping bell curves—one for males and one for females—representing their respective height distributions.
Calculating Likelihoods and Making Classification
Decisions
Let's walk through an example of classifying a person's height, say , assuming we have already estimated the Gaussian parameters ( ) for Male and Female height distributions.
Step 1: Compute Class-Conditional Likelihoods For each class, we calculate the value of its Gaussian Probability Density Function (PDF) at the observed height.
i ∈ C = c
i ∈ C = c
Estimation (MLE)
For Gaussian Classifiers, estimating the optimal mean vectors ( ) and covariance matrices ( ) for all classes typically uses Maximum Likelihood Estimation (MLE). MLE seeks parameter values that maximize the overall probability of observing the entire labeled training dataset.
The total log-likelihood to be maximized is given by:
This can be further decomposed into two sums:
Here, represents all parameters to be estimated, including the mean vectors and covariance matrices for each class:.
Sufficient Statistics for Gaussian Parameters:
A key advantage for Gaussian distributions is that their parameters can be efficiently estimated from just a few sufficient statistics for each class c. These are simple aggregate values calculated from the training samples belonging to that class:
i =
n
i =
n
i =
n
Understanding Decision Boundaries
The decision boundary is a crucial concept in classification: a theoretical surface (line, plane, or hyperplane) in feature space where a classifier's prediction switches classes. For Bayes classifiers, this boundary occurs where the posterior probabilities of the two most likely classes are exactly equal.
Binary Classification Case (Class 0 and Class 1):
For a two-class problem, the decision boundary is where posterior probabilities are equal:
. This is equivalent to the posterior probability ratio being 1:.
Using Bayes' Theorem and taking logarithms, this simplifies to the point where the Log-Likelihood Ratio (LLR) equals the log of the prior probability ratio:
For Gaussian classifiers (each with its own full covariance matrix ) , this Log-Likelihood Ratio simplifies to a quadratic function of the input feature vector (^) x :
Setting this quadratic function to a constant defines a quadratic decision boundary. In a 2D feature space, these boundaries can take the shape of various curves like parabolas, ellipses, or hyperbolas.
Visual Representation:
Simplifying Assumption: Naive Bayes (Diagonal
Covariance)
Core Assumption: The Naive Bayes classifier assumes that all features are conditionally independent given the class. This implies that within any specific class, one feature's value does not depend on another's.
Consequence of Assumption: Due to this conditional independence, the covariance matrix for each class ( ) is forced to be diagonal. A diagonal matrix has non-zero values only on its main diagonal, meaning all off-diagonal (covariance) terms are zero, indicating uncorrelated features.
Simplification of PDF: With a diagonal covariance matrix, the complex multivariate Gaussian PDF simplifies dramatically into a simple product of univariate (single-feature) Gaussian PDFs:
Here, is the total number of features. This product form is much simpler to compute and estimate.
Decision Boundary Shape: While the underlying mathematical form of the Log-Likelihood Ratio (LLR) remains quadratic, the diagonal covariance matrix's specific properties lead to particular decision boundary shapes. These often appear as axis-aligned ellipses, hyperbolas, or parabolas , reflecting the lack of correlation between features.
Visual Representation:
Naive Bayes (Diagonal Covariance)
Feature 1
Class 1 Data - Axis-Aligned Ellipse
Curved, often Axis-Aligned Decision Boundary
Class 2 Data - Axis-Aligned Ellipse
Feature 2
j =
D
Simplifying Assumption: Tied Covariance
Assumption: The Tied Covariance model assumes that all classes share the exact same covariance matrix ; thus, for all classes c. Crucially, their mean vectors ( ) can still differ, meaning classes can be centered in different locations but maintain the same "shape" and "orientation" of their data distribution.
Consequence: When this assumption holds, a remarkable simplification occurs in the Log-Likelihood Ratio (LLR): the quadratic terms ( ) cancel out because the shared covariance matrix makes them identical for all classes.
Simplification to Linear Function: Consequently, the LLR simplifies to a purely linear function of the input feature vector x :
Decision Boundary Shape: Setting this linear function to a constant defines linear decision boundaries. In a 2D feature space, these are straight lines; in higher dimensions, they are hyperplanes. This model is mathematically equivalent to Linear Discriminant Analysis (LDA) when applied in a generative context.
Visual Representation:
Tied Covariance (Linear Boundaries / LDA)
Feature 1
Class 1 Data - Same Shape
Straight Line Decision Boundary
Class 2 Data - Same Shape
Feature 2
Model Raw (No PCA) PCA (Features: 50) PCA (Features: 9)
Naive Gaussian 12.2% 12.3% 23.4% Gaussian (Full Cov.) 4.3% 3.6% 12.2%
Key Observations from the Results Table:
Full Covariance Model Performance: The Gaussian (Full Cov.) model consistently achieves the best performance. Note its error rate of 4.3% with raw features, which even slightly improves to 3.6% when PCA reduces features to 50 dimensions. Interpretation: This superior performance indicates that the distinct "shapes" or orientations (captured by unique covariance matrices) of the data distributions for each handwritten digit class are highly discriminative. Accounting for specific correlations between pixels within each digit is crucial for optimal accuracy. Impact of PCA Dimensionality Reduction: Applying a moderate amount of PCA (e.g., reducing to 50 features) can actually improve performance (as seen with the Full Gaussian model, from 4.3% to 3.6%). This suggests PCA effectively removes noise or redundant dimensions without losing critical information. However, aggressive dimensionality reduction (e.g., down to just 9 features) significantly increases the error rate across all models. This clearly demonstrates that reducing features too much can lead to the loss of vital discriminative information needed to distinguish digits. Naive Bayes Model Performance: The Naive Gaussian and Naive Tied Gaussian models generally perform poorly compared to the full covariance and tied covariance models. Interpretation: This poor performance likely stems from the significant violation of the conditional independence assumption in image data. Pixels in handwritten digits are highly correlated (e.g., neighboring pixels often have similar values), and the Naive Bayes assumption ignores these crucial dependencies, leading to suboptimal classification. Tied Covariance (LDA) Model Performance: While better than the Naive Bayes models, the Tied Gaussian (LDA) model still performs worse than the Full Covariance model. Interpretation: This suggests that forcing all digit classes to share identical covariance "shapes" is too restrictive for this dataset. The nuances in how different digits are written (e.g., the spread of a '0' versus a '1') are lost when a single, common covariance matrix is assumed.
Summary of Generative Gaussian Models for
Classification
Here's a concise summary of key takeaways regarding generative Gaussian models for classification:
Model Complexity Choice Guidelines: Full-covariance Gaussian Model: This is generally the preferred choice when classes are expected to have distinct and complex "shapes" or orientations in feature space, and sufficient training data is available per class to reliably estimate individual covariance matrices. Tied Covariance Model (Equivalent to LDA): A good option when classes are believed to have broadly similar shapes or spreads in feature space, or when training data per class is limited (pooling data for a single covariance matrix can lead to more robust estimates). It inherently results in linear decision boundaries , which are computationally simpler and more interpretable. Naive Bayes Model (Diagonal Covariance): Best applied with very high-dimensional and sparse data (e.g., text data) or when features are reasonably believed to be uncorrelated within classes. Risk: Be aware of significant accuracy loss if strong correlations genuinely exist between features, as the model explicitly ignores them. Role of Dimensionality Reduction (e.g., PCA): Techniques like PCA are valuable preprocessing steps. They can reduce computational costs and memory requirements, and potentially enhance generalization by removing noise or redundant information. Crucial Consideration: Avoid excessive dimensionality reduction, as this can lead to the loss of critical discriminative information. Core of the Generative Approach: The fundamental principle of Gaussian classifiers, and generative models in general, is to learn the data distribution for each class ( ). These learned class-conditional distributions are then combined with class prior probabilities ( ) using Bayes' Theorem to calculate the posterior probabilities ( ). These posterior probabilities are subsequently used to make robust and probabilistically informed classification decisions.