Can I have an example of a GDA classifier for 2D data
Assistant
Certainly! Gaussian Discriminant Analysis (GDA) is a probabilistic classification model that assumes the feature distributions for each class are Gaussian (normal distribution). In GDA, we model the conditional probability ( p(x | y) ) for each class ( y ), and use Bayes' theorem to compute the posterior probability ( p(y | x) ) for classification.
Below is an example of how to construct a GDA classifier for 2D data.
Example of GDA Classifier for 2D Data
Suppose we have a dataset with two classes, ( y \in {0, 1} ), and each data point ( x \in \mathbb{R}^2 ).
Dataset:
Class 0 ( ( y = 0 ) ):
Data Point
( x_1 )
( x_2 )
( x^{(1)} )
1
2
( x^{(2)} )
2
1
( x^{(3)} )
2
3
( x^{(4)} )
3
2
Class 1 ( ( y = 1 ) ):
Data Point
( x_1 )
( x_2 )
( x^{(5)} )
6
5
( x^{(6)} )
7
6
( x^{(7)} )
6
7
( x^{(8)} )
5
6
Step 1: Estimate the Parameters
We need to estimate the following parameters:
Class Priors: ( \phi = P(y = 1) ) and ( P(y = 0) = 1 - \phi )
Class Means: ( \mu_0 ) and ( \mu_1 )
Shared Covariance Matrix: ( \Sigma )
Compute Class Priors ( \phi ):
Total number of samples, ( n = 8 )
Number of samples from Class 1, ( n_1 = 4 ); thus, ( n_0 = n - n_1 = 4 )
Using the estimated parameters, we can derive the discriminant function ( \delta(x) ) for GDA. Since the covariances are shared and the covariance matrix is the same for both classes, the decision boundary will be linear.
( \delta(x) > 0 ), so ( x ) is classified as Class 1 ( ( y = 1 ) ).
Step 4: Plot the Decision Boundary
The decision boundary is defined by ( \delta(x) = 0 ):
[
8x_1 + 8x_2 - 64 = 0 \implies x_1 + x_2 = 8
]
This is a straight line in the 2D feature space.
Visualization Description:
Data Points:
Class 0: Points around ( (2, 2) ).
Class 1: Points around ( (6, 6) ).
Decision Boundary:
A straight line passing through points where ( x_1 + x_2 = 8 ).
It separates the feature space into two regions:
Left/below the line: Class 0.
Right/above the line: Class 1.
Conclusion
In this example, we've constructed a GDA classifier for 2D data by:
Estimating parameters (class priors, class means, covariance matrix) from the given data.
Deriving the discriminant function using these parameters.
Classifying new data points based on the sign of the discriminant function.
Identifying the decision boundary, which is linear due to the shared covariance assumption.
This approach demonstrates how GDA can effectively model and classify data when the class-conditional distributions can be assumed Gaussian with shared covariance, leading to a linear decision boundary in the feature space.
Note: In practice, you would typically use more data and potentially not assume that the classes share the same covariance matrix (leading to Quadratic Discriminant Analysis if covariances differ). However, for illustrative purposes, this example demonstrates the core concepts of GDA for 2D data.