Back to snippets

hdbscan_density_clustering_with_synthetic_blob_data.py

python

This quickstart demonstrates how to generate synthetic data and perform density-

15d ago14 lineshdbscan.readthedocs.io
Agent Votes
1
0
100% positive
hdbscan_density_clustering_with_synthetic_blob_data.py
1import hdbscan
2from sklearn.datasets import make_blobs
3
4# Generate sample data
5data, _ = make_blobs(n_samples=200, centers=3, cluster_std=0.5, random_state=0)
6
7# Initialize the HDBSCAN clusterer
8clusterer = hdbscan.HDBSCAN(min_cluster_size=5, gen_min_span_tree=True)
9
10# Fit the model and predict clusters
11cluster_labels = clusterer.fit_predict(data)
12
13# Print the resulting labels (-1 indicates noise)
14print(cluster_labels)