Package: hdbscan
HDBSCANHDBSCAN - Hierarchical Density-Based Spatial Clustering of Applications
with Noise. Performs DBSCAN over varying epsilon values and integrates
the result to find a clustering that gives the best stability over epsilon.
This allows HDBSCAN to find clusters of varying densities (unlike DBSCAN),
and be more robust to parameter selection.In practice this means that HDBSCAN returns a good clustering straight
away with little or no parameter tuning – and the primary parameter,
minimum cluster size, is intuitive and easy to select.HDBSCAN is ideal for exploratory data analysis; it’s a fast and robust
algorithm that you can trust to return meaningful clusters (if there
are any).Based on the papers:McInnes L, Healy J.Accelerated Hierarchical Density Based ClusteringIn: 2017 IEEE International Conference on Data Mining Workshops (ICDMW), IEEE, pp 33-42.
2017[pdf]R. Campello, D. Moulavi, and J. Sander,Density-Based Clustering Based on
Hierarchical Density EstimatesIn: Advances in Knowledge Discovery and Data Mining, Springer, pp 160-172.
2013Documentation, including tutorials, are available on ReadTheDocs athttp://hdbscan.readthedocs.io/en/latest/.Notebookscomparing HDBSCAN to other clustering algorithms, explaininghow HDBSCAN worksandcomparing performance with other python clustering implementationsare available.How to use HDBSCANThe hdbscan package inherits from sklearn classes, and thus drops in neatly
next to other sklearn clusterers with an identical calling API. Similarly it
supports input in a variety of formats: an array (or pandas dataframe, or
sparse matrix) of shape(num_samples x num_features); an array (or sparse matrix)
giving a distance matrix between samples.importhdbscanfromsklearn.datasetsimportmake_blobsdata,_=make_blobs(1000)clusterer=hdbscan.HDBSCAN(min_cluster_size=10)cluster_labels=clusterer.fit_predict(data)PerformanceSignificant effort has been put into making the hdbscan implementation as fast as
possible. It isorders of magnitude faster than the reference implementationin Java,
and is currently faster than highly optimized single linkage implementations in C and C++.version 0.7 performance can be seen in this notebook.
In particularperformance on low dimensional data is better than sklearn’s DBSCAN,
and via support for caching with joblib, re-clustering with different parameters
can be almost free.Additional functionalityThe hdbscan package comes equipped with visualization tools to help you
understand your clustering results. After fitting data the clusterer
object has attributes for:The condensed cluster hierarchyThe robust single linkage cluster hierarchyThe reachability distance minimal spanning treeAll of which come equipped with methods for plotting and converting
to Pandas or NetworkX for further analysis. See the notebook onhow HDBSCAN worksfor examples and further details.The clusterer objects also have an attribute providing cluster membership
strengths, resulting in optional soft clustering (and no further compute
expense). Finally each cluster also receives a persistence score giving
the stability of the cluster over the range of distance scales present
in the data. This provides a measure of the relative strength of clusters.Outlier DetectionThe HDBSCAN clusterer objects also support the GLOSH outlier detection algorithm.
After fitting the clusterer to data the outlier scores can be accessed via theoutlier_scores_attribute. The result is a vector of score values, one for
each data point that was fit. Higher scores represent more outlier like objects.
Selecting outliers via upper quantiles is often a good approach.Based on the paper:R.J.G.B. Campello, D. Moulavi, A. Zimek and J. SanderHierarchical Density Estimates for Data Clustering, Visualization, and Outlier Detection,
ACM Trans. on Knowledge Discovery from Data, Vol 10, 1 (July 2015), 1-51.Robust single linkageThe hdbscan package also provides support for therobust single linkageclustering algorithm of Chaudhuri and Dasgupta. As with the HDBSCAN
implementation this is a high performance version of the algorithm
outperforming scipy’s standard single linkage implementation. The
robust single linkage hierarchy is available as an attribute of
the robust single linkage clusterer, again with the ability to plot
or export the hierarchy, and to extract flat clusterings at a given
cut level and gamma value.Example usage:importhdbscanfromsklearn.datasetsimportmake_blobsdata,_=make_blobs(1000)clusterer=hdbscan.RobustSingleLinkage(cut=0.125,k=7)cluster_labels=clusterer.fit_predict(data)hierarchy=clusterer.cluster_hierarchy_alt_labels=hierarchy.get_clusters(0.100,5)hierarchy.plot()Based on the paper:K. Chaudhuri and S. Dasgupta.“Rates of convergence for the cluster tree.”In Advances in Neural Information Processing Systems, 2010.InstallingEasiest install, if you have Anaconda (thanks to conda-forge which is awesome!):condainstall-cconda-forgehdbscanPyPI install, presuming you have an up to date pip:pipinstallhdbscanBinary wheels for a number of platforms are available thanks to the work of
Ryan Helinski <rlhelinski@gmail.com>.If pip is having difficulties pulling the dependencies then we’d suggest to first upgrade
pip to at least version 10 and try again:pipinstall--upgradepippipinstallhdbscanOtherwise install the dependencies manually using anaconda followed by pulling hdbscan from pip:condainstallcythoncondainstallnumpyscipycondainstallscikit-learnpipinstallhdbscanFor a manual install of the latest code directly from GitHub:pipinstall--upgradegit+https://github.com/scikit-learn-contrib/hdbscan.git#egg=hdbscanAlternatively download the package, install requirements, and manually run the installer:wgethttps://github.com/scikit-learn-contrib/hdbscan/archive/master.zipunzipmaster.ziprmmaster.zipcdhdbscan-masterpipinstall-rrequirements.txtpythonsetup.pyinstallRunning the TestsThe package tests can be run after installation using the command:nosetests-shdbscanor, ifnoseis installed butnosetestsis not in yourPATHvariable:python-mnose-shdbscanIf one or more of the tests fail, please report a bug athttps://github.com/scikit-learn-contrib/hdbscan/issues/newPython VersionThe hdbscan library supports both Python 2 and Python 3. However we recommend Python 3 as the better option if it is available to you.Help and SupportFor simple issues you can consult theFAQin the documentation.
If your issue is not suitably resolved there, please check theissueson github. Finally, if no solution is available there feel free toopen an issue; the authors will attempt to respond in a reasonably timely fashion.ContributingWe welcome contributions in any form! Assistance with documentation, particularly expanding tutorials,
is always welcome. To contribute pleasefork the projectmake your changes and submit a pull request. We will do our best to work through any issues with
you and get your code merged into the main branch.CitingIf you have used this codebase in a scientific publication and wish to cite it, please use theJournal of Open Source Software article.L. McInnes, J. Healy, S. Astels,hdbscan: Hierarchical density based clusteringIn: Journal of Open Source Software, The Open Journal, volume 2, number 11.
2017@article{mcinnes2017hdbscan,title={hdbscan: Hierarchical density based clustering},author={McInnes, Leland and Healy, John and Astels, Steve},journal={The Journal of Open Source Software},volume={2},number={11},pages={205},year={2017}}To reference the high performance algorithm developed in this library please cite our paper in ICDMW 2017 proceedings.McInnes L, Healy J.Accelerated Hierarchical Density Based ClusteringIn: 2017 IEEE International Conference on Data Mining Workshops (ICDMW), IEEE, pp 33-42.
2017@inproceedings{mcinnes2017accelerated,title={Accelerated Hierarchical Density Based Clustering},author={McInnes, Leland and Healy, John},booktitle={Data Mining Workshops (ICDMW), 2017 IEEE International Conference on},pages={33--42},year={2017},organization={IEEE}}LicensingThe hdbscan package is 3-clause BSD licensed. Enjoy.