Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Science
  • Data Science Projects
  • Data Analysis
  • Data Visualization
  • Machine Learning
  • ML Projects
  • Deep Learning
  • NLP
  • Computer Vision
  • Artificial Intelligence
Open In App
Next Article:
Dirichlet Process Mixture Models (DPMMs)
Next article icon

Dirichlet Process Mixture Models (DPMMs)

Last Updated : 18 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Dirichlet Process Mixture Models (DPMMs) is a flexible clustering method that can automatically decide the number of clusters based on the data. Unlike traditional methods like K-means which require you to specify the number of clusters.

It offers a probabilistic and nonparametric approach to clustering which allows the model to figure out number of groups on its own based complexity of the data.

Key Concepts in DPMMs

To understand DPMMs it's important to understand two key concepts:

1. Beta Distribution

The Beta distribution models probabilities for two possible outcomes such as success or failure. It is defined by two parameters α and β that shape the distribution. The probability density function (PDF) is given by:

f(x,\alpha,\beta) = \frac{x^{\alpha-1}(1-x)^{\beta-1}}{\Beta(\alpha\beta)}

Where B(α, β) is the beta function.

2. Dirichlet Distribution

The Dirichlet distribution is a generalization of the Beta distribution for multiple outcomes. It represents the probabilities of different categories like rolling a dice with unknown probabilities for each side. The PDF of the Dirichlet distribution is:

f(p,\alpha) = \frac{1}{B(\alpha)}\Pi_{i=1}^{k}p_i^{\alpha_i -1}

  • p=(p1​,p2​,…, pK​) is a vector representing a probability distribution over K categories. Each pi​ is a probability and ∑K​pi​=1.
  • α=(α1​,α2​,…,αK​) is a vector of positive shape parameters. This determines the shape of the distribution
  • B(α) is a beta function.

How α Affects the Distribution

  • Higher α values result in probabilities concentrated around the mean.
  • Equal α values produce symmetric distributions.
  • Different α values create skewed distributions.

Dirichlet Process (DP)

A Dirichlet Process is a stochastic process that generates probability distributions over infinite categories. It enables clustering without specifying the number of clusters in advance. The Dirichlet Process is defined as:

DP(α,G0 )

Where:

  • α: Concentration parameter controlling cluster diversity.
  • G₀: Base distribution representing the prior belief about cluster parameters.

Stick-Breaking Process

The stick-breaking process is a method to generate probabilities from a Dirichlet Process. The concept is shown in the image below:

file
Stick-Breaking Process
  • We take a stick of length unit 1 representing our base probability distribution
  • Using marginal distribution property we break it into two. We use beta distribution. Suppose the length obtained is p1
  • The conditional probability of the remaining categories is a Dirichlet distribution
  • The length of the stick that remains is 1-p1 and using the marginal property again
  • Repeat the above steps to obtain enough pi such that the sum is close to 1
  • Mathematically this can be expressed as
    • For k=1,p1=β(1,α)
    • For k=2,p2=β(1,α)∗(1−p1)
    • For k=3,p3=β(1,α)∗(1−p1−p2)

For each categories sample we also sample μ from our base distribution. This becomes our cluster parameters.

How DPMMs Work?

DPMM is an extension of Gaussian Mixture Models where the number of clusters is not fixed. It uses the Dirichlet Process as a prior for the mixture components.

  1. Initialize: Assign random clusters to data points.
  2. Iteration:
    • Pick one data point.
    • Fix other cluster assignments.
    • Assign the point to an existing cluster or a new cluster based on probabilities.
  3. Repeat: Continue until cluster assignments no longer change.

The probability of assigning a point to an existing cluster is: \frac{n_k}{n-1+\alpha} \Nu (\mu,1)

The probability of assigning a point to a new cluster is: \frac{\alpha}{n-1+\alpha}\Nu(0,1)

Where:

  • nₖ: Number of points in cluster k.
  • α: Concentration parameter.
  • N(μ, σ): Gaussian distribution.

DPMM is an extension of Gaussian Mixture Models where the number of clusters is not fixed. It uses the Dirichlet Process as a prior for the mixture components.

Implementing Dirichlet Process Mixture Models using Sklearn

Now let us implement DPMM process in scikit learn and we'll use the Mall Customers Segmentation Data. Let's understand this step-by-step:

Step 1: Import Libraries and Load Dataset

In this step we will import all the necessary libraries. This dataset contains customer information, including age, income and spending score. You can download the dataset from here.

Python
import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.mixture import BayesianGaussianMixture from sklearn.decomposition import PCA   data = pd.read_csv('/content/Mall_Customers (1).csv') print(data.head()) 

Output:

dataset
Dataset

Step 2: Feature Selection

In this step we select features that are likely to influence customer clusters.

Python
X = data[['Age', 'Annual Income (k$)', 'Spending Score (1-100)']].values 

Step 3: Dimensionality Reduction

We will use PCA algorithm to reduces the data's dimensions to 2 for easy visualization.

Python
pca = PCA(n_components=2) X_pca = pca.fit_transform(X) 

Step 4: Fit Bayesian Gaussian Mixture Model

The model automatically determines the optimal number of clusters based on the data.

Python
dpmm = BayesianGaussianMixture(     n_components=10,               covariance_type='full',     weight_concentration_prior_type='dirichlet_process',     weight_concentration_prior=1e-2,       random_state=42 )  dpmm.fit(X) labels = dpmm.predict(X) 

Step 5: Visualization

Clusters are visualized with different colors making patterns easier to interpret.

Python
plt.figure(figsize=(8, 6)) plt.scatter(X_pca[:, 0], X_pca[:, 1], c=labels, cmap=plt.cm.Paired, edgecolors='k', s=100, linewidth=1.5) plt.title('Dirichlet Process Mixture Model Clustering') plt.xlabel('PCA Component 1') plt.ylabel('PCA Component 2') plt.grid(True) plt.show() 

Output:

DPMM
DPMM

The clustering of mall customers using DPMM highlights distinct groups where average customers in the center and extreme spenders on the edges. Overlapping clusters suggest some customers share similar behaviors.

Advantages over Traditional Methods

  • One of the primary advantage of DPMMs is their ability to automatically determine the number of clusters in the data. Traditional methods often require the pre-specification of the number of clusters like in k-means which can be challenging in real-world applications.
  • It operate within a probabilistic framework allowing for the quantification of uncertainty. Traditional methods often provide "hard" assignments of data points to clusters while DPMMs give probabilistic cluster assignments capturing the uncertainty inherent in the data.
  • DPMMs find applications in a wide range of fields including natural language processing, computer vision, bioinformatics and finance. Their flexibility makes them applicable to diverse datasets and problem domains.

Next Article
Dirichlet Process Mixture Models (DPMMs)

R

rahulsm27
Improve
Article Tags :
  • Machine Learning
  • Geeks Premier League
  • AI-ML-DS
  • Geeks Premier League 2023
Practice Tags :
  • Machine Learning

Similar Reads

    How do diffusion models use iterative processes to generate images?
    In recent years, diffusion models have emerged as a powerful class of generative models, particularly for tasks such as image generation. These models rely on iterative processes to transform noise into coherent images, leveraging principles from probability theory and stochastic processes. This art
    5 min read
    What are Evolutionary Process Models?
    Evolutionary model is a combination of Iterative and Incremental model of software development life cycle. In this article, we are going to understand different types of evolutionary process models with the help of examples. Software Process ModelA software process model is a structured representati
    5 min read
    Gaussian Mixture Models (GMM) in Scikit Learn
    Gaussian Mixture Model (GMM) is a flexible clustering technique that models data as a mixture of multiple Gaussian distributions. Unlike k-means which assumes spherical clusters GMM allows clusters to take various shapes making it more effective for complex datasets.If you're new to GMM you can refe
    4 min read
    Dirichlet Distribution in R
    The Dirichlet distribution is a multivariate generalization of the Beta distribution and is commonly used in Bayesian statistics, machine learning, and other fields where probability distributions over multiple categories are required. This article provides an in-depth understanding of the Dirichlet
    4 min read
    What is Gaussian mixture model clustering using R
    Gaussian mixture model (GMM) clustering is a used technique in unsupervised machine learning that groups data points based on their probability distributions. In R Programming Language versatility lies in its ability to model clusters of shapes and sizes making it applicable to scenarios. The approa
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences