Gaussian Mixture Models (GMM) are a probabilistic approach to clustering based on the assumption that data points are generated from a mixture of several Gaussian distributions. Unlike K-Means, GMMs provide soft clustering — meaning each data point belongs to multiple clusters with certain probabilities.
GMMs are especially useful when:
A GMM models data as a mixture of multiple multivariate Gaussian distributions. Each Gaussian is defined by:
The model estimates parameters using the Expectation-Maximization (EM) algorithm:
| Feature | Description |
|---|---|
| Type | Probabilistic model |
| Clustering style | Soft (fuzzy) clustering |
| Distribution | Mixture of Gaussians |
| Suitable for | Non-spherical, overlapping, probabilistic data |
| Output | Probability of each point in each cluster |
sklearnfrom sklearn.mixture import GaussianMixture
from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt
import numpy as np
# Generate synthetic data
X, y_true = make_blobs(n_samples=300, centers=3, cluster_std=1.0, random_state=42)
# Fit GMM
gmm = GaussianMixture(n_components=3, random_state=42)
gmm.fit(X)
# Predict cluster probabilities and labels
probs = gmm.predict_proba(X)
labels = gmm.predict(X)
# Visualize results
plt.figure(figsize=(8, 5))
plt.scatter(X[:, 0], X[:, 1], c=labels, s=40, cmap='viridis')
plt.title("Gaussian Mixture Model Clustering")
plt.xlabel("Feature 1")
plt.ylabel("Feature 2")
plt.grid(True)
plt.show()Output-
make_blobs: Generates synthetic data with clear clustersGaussianMixture: Trains GMM on datapredict: Assigns most likely clusterpredict_proba: Gives probabilities of cluster membershipsAIC and BIC to choose the optimal number of componentscovariance_type values (full, tied, diag, spherical)Gaussian Mixture Models provide a flexible, probabilistic way to perform clustering. They go beyond hard assignments by modeling overlapping clusters using Gaussian distributions. GMMs are a great choice for tasks where clusters are not clearly separated or when you need confidence scores for predictions.
Sign in to join the discussion and post comments.
Sign in