Prerequisites: Gaussian Mixture
A Gaussian Mixture Model assumes the data to be segregated into clusters in such a way that each data point in a given cluster follows a particular Multi-variate Gaussian distribution and the Multi-Variate Gaussian distributions of each cluster is independent of one another. To cluster data in such a model, the posterior probability of a data-point belonging to a given cluster given the observed data needs to be calculated. An approximate method for this purpose is the Baye's method. But for large datasets, the calculation of marginal probabilities is very tedious. As there is only a need to find the most probable cluster for a given point, approximation methods can be used as they reduce the mechanical work. One of the best approximate methods is to use the Variational Bayesian Inference method. The method uses the concepts of
KL Divergence and
Mean-Field Approximation.
The below steps will demonstrate how to implement Variational Bayesian Inference in a Gaussian Mixture Model using Sklearn. The data used is the
Credit Card data which can be downloaded from Kaggle.
Step 1: Importing the required libraries
Step 2: Loading and Cleaning the data
👁 Image
Step 3: Pre-processing the data
👁 Image
Step 4: Reducing the dimensionality of the data to make it visualizable
The primary two parameters of the Bayesian Gaussian Mixture Class are
n_components and
covariance_type.
- n_components: It determines the maximum number of clusters in the given data.
- covariance_type: It describes the type of covariance parameters to be used.
You can read about all the other attributes in it's
documentation.
In the below-given steps, the parameter n_components will be fixed at 5 while the parameter covariance_type will be varied for all possible values to visualize the impact of this parameter on the clustering.
Step 5: Building clustering models for different values of covariance_type and visualizing the results
a)
covariance_type = 'full'
b)
covariance_type = 'tied'
c)
covariance_type = 'diag'
d)
covariance_type = 'spherical'