How to extract unsupervised clusters from a Dirichlet Process in PyMC3?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Clustering is a fundamental technique in data analysis, where the objective is to group a set of objects in such a way that objects in the same group, called a cluster, are more similar than those in other groups. Unsupervised clustering with a Dirichlet Process (DP) is a powerful approach to infer the number of clusters in the data instead of predefining them. In this article, we will explore how to extract unsupervised clusters using a Dirichlet Process in PyMC3, a Python library for Bayesian statistical modeling.
Understanding Dirichlet Processes
What is a Dirichlet Process?
The Dirichlet Process is a stochastic process used in Bayesian nonparametric models. It is particularly useful for problems where the number of mixture components (clusters) is unknown and is instead treated as a random variable. The amount of flexibility allowed by DPs makes them a potent tool for clustering problems.
Mathematically, a Dirichlet Process is a distribution over distributions. It is characterized by a base distribution and a concentration parameter . The concentration parameter indicates how strongly the DP tends to concentrate on the base distribution — a high value of means more clusters, while a low value tends to produce fewer clusters.
Chinese Restaurant Process
The Dirichlet Process can be visualized through the analogy of a Chinese Restaurant Process (CRP). Imagine an infinitely long table in a restaurant. The first customer sits at the first table; subsequent customers either join an existing table with a probability proportional to the number of people already sitting there or start a new table with a probability proportional to .
Implementing Dirichlet Process Clustering in PyMC3
PyMC3 provides the tools needed to model a Dirichlet Process. The following example demonstrates how to implement unsupervised clustering using a DP in PyMC3.
- We define a PyMC3 model which includes a DP. The hyperparameter is modeled with a Gamma distribution, which provides the base concentration for the model.
- A stick-breaking process is employed. Here, each component's prior weight is constructed recursively.
- The means and standard deviations of the potential clusters are defined as normal and half-normal distributions.
Related reading
- How to feed back `RNN` output to input in tensorflow
- How to feed input with changing size in Tensorflow
- How to feed into LSTM with 4 dimensional input?
- How to feed into LSTM with 4 dimensional input?
- How to fetch vectors for a word list with Word2Vec?
- How to find a dense region in 1d
- How to find an optimum number of processes in GridSearchCV ..., n_jobs ... ?
- How to find the corresponding class in clf.predict_proba
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.