hdbscan is a clustering algorithm developed by Campello, Moulavi, and Zimek that extends DBSCAN by converting it into a hierarchical clustering algorithm, then using a technique to extract a flat partitioning from the hierarchy. It handles varying density clusters and can identify noise points. The current version is 0.8.42, with frequent minor releases addressing bugs and adding small features.
pip install hdbscanVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `hdbscan.HDBSCAN` to perform clustering on sample data. It initializes the model with key parameters `min_cluster_size` and `min_samples`, then fits the data and retrieves cluster labels. Labels of -1 indicate noise points.
Upgrade hdbscan to version 0.8.38 or later using `pip install --upgrade hdbscan`.
Upgrade to Python 3.8 or a newer supported version (e.g., Python 3.10, 3.11, 3.12).
Experiment with different values, potentially using grid search or visual inspection of clusterings (e.g., using `clusterer.condensed_tree_.plot()` for insight) to find optimal parameters for your specific dataset and problem.
Be aware that results from versions 0.8.38 and later may not be directly comparable to those from earlier versions due to this algorithmic enhancement. Re-evaluate models if upgrading.
Upgrade to hdbscan 0.8.42 or later if you depend on accurate outlier scores.
Ensure `hdbscan` is installed using `pip install hdbscan` or `conda install -c conda-forge hdbscan`. If installed, check your Python environment or rename any local `hdbscan.py` file.
For Windows, install 'Microsoft C++ Build Tools' from Visual Studio. Ensure `Cython`, `numpy`, `scipy`, and `scikit-learn` are pre-installed and up-to-date (`pip install cython numpy scipy scikit-learn`). Consider using `conda install -c conda-forge hdbscan` for a more reliable installation, especially if using Anaconda. For Linux, install `build-essential` or `gcc`.
Set `min_cluster_size` to an integer value greater than 1, for example, `hdbscan.HDBSCAN(min_cluster_size=2)`.
To use `approximate_predict`, import it directly: `from hdbscan.prediction import approximate_predict` and call it with the fitted clusterer and new data: `labels, probabilities = approximate_predict(clusterer, new_data)`. Alternatively, ensure `prediction_data=True` was set during model initialization if you intend to access prediction-related attributes directly on the model (though `approximate_predict` is a separate function).
Ensure `clusterer.fit(data)` or `clusterer.fit_predict(data)` has been called before attempting to access `clusterer.labels_`.