Implementation:Scikit learn Scikit learn Birch
| Knowledge Sources | |
|---|---|
| Domains | Clustering, Online Learning |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for performing memory-efficient online-learning clustering using the BIRCH algorithm provided by scikit-learn.
Description
Birch (Balanced Iterative Reducing and Clustering using Hierarchies) is an online-learning clustering algorithm that builds a tree data structure called a Clustering Feature (CF) tree. It incrementally processes data points, inserting them into a compact summary representation. The leaf nodes of the CF tree contain subclusters whose centroids can serve as final cluster centers or as input to another clustering algorithm such as AgglomerativeClustering. It is designed as a memory-efficient alternative to MiniBatchKMeans.
Usage
Use Birch when you have large datasets that cannot fit in memory, when you need an online (incremental) clustering algorithm, or when you want a first pass to reduce data dimensionality before applying a more expensive clustering algorithm. It is particularly effective for data that has a natural spherical cluster structure.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/cluster/_birch.py
Signature
class Birch(
ClassNamePrefixFeaturesOutMixin, ClusterMixin, TransformerMixin, BaseEstimator
):
def __init__(
self,
*,
threshold=0.5,
branching_factor=50,
n_clusters=3,
compute_labels=True,
):
Import
from sklearn.cluster import Birch
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| threshold | float | No | Maximum radius of a subcluster for merging. Lower values promote splitting. Default is 0.5. |
| branching_factor | int | No | Maximum number of CF subclusters in each node. Default is 50. |
| n_clusters | int, sklearn.cluster model, or None | No | Number of clusters after the final clustering step. Can also be a clustering model instance. Default is 3. |
| compute_labels | bool | No | Whether to compute labels for each fit. Default is True. |
Outputs
| Name | Type | Description |
|---|---|---|
| root_ | _CFNode | Root of the CF tree. |
| dummy_leaf_ | _CFNode | Pointer to the first leaf in the CF tree. |
| subcluster_centers_ | ndarray | Centroids of all subclusters read from leaves. |
| subcluster_labels_ | ndarray | Labels assigned to the subcluster centroids. |
| labels_ | ndarray of shape (n_samples,) | Cluster labels for each sample (if compute_labels=True). |
Usage Examples
Basic Usage
from sklearn.cluster import Birch
import numpy as np
X = np.array([[1, 2], [1, 4], [1, 0],
[10, 2], [10, 4], [10, 0]])
brc = Birch(n_clusters=2)
brc.fit(X)
print(brc.labels_)
print(brc.subcluster_centers_)