HDBSCAN
- class sklearn.cluster.HDBSCAN(min_cluster_size=5, min_samples=None, cluster_selection_epsilon=0.0, max_cluster_size=None, metric='euclidean', metric_params=None, , , , , , , ,
Cluster data using hierarchical density-based clustering.
HDBSCAN - 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.
Read more in the User Guide.
The minimum number of samples in a group for that group to be considered a cluster; groupings smaller than this size will be left as noise.
The parameter k used to calculate the distance between a point
x_p and its k-th nearest neighbor.
When None, defaults to min_cluster_size.
A distance threshold. Clusters below this value will be merged. See [5] for more information.
A limit to the size of clusters returned by the "eom" cluster
selection algorithm. There is no limit when max_cluster_size=None.
Has no effect if cluster_selection_method="leaf".
The metric to use when calculating distance between instances in a feature array.
If metric is a string or callable, it must be one of
the options allowed by pairwise_distances
for its metric parameter.
If metric is “precomputed”, X is assumed to be a distance matrix and must be square.
Arguments passed to the distance metric.
A distance scaling parameter as used in robust single linkage. See [3] for more information.
Exactly which algorithm to use for computing core distances; By default
this is set to "auto" which attempts to use a
KDTree tree if possible, otherwise it uses
a BallTree tree. Both "kd_tree" and
"ball_tree" algorithms use the
NearestNeighbors estimator.
If the X passed during is sparse or is invalid for
both and
, then it resolves to use the
algorithm.
Leaf size for trees responsible for fast nearest neighbour queries when
a KDTree or a BallTree are used as core-distance algorithms. A large
dataset size and small leaf_size may induce excessive memory usage.
If you are running out of memory consider increasing the leaf_size
parameter. Ignored for algorithm="brute".
Number of jobs to run in parallel to calculate distances.
None means 1 unless in a joblib.parallel_backend context.
-1 means using all processors. See Glossary
for more details.
The method used to select clusters from the condensed tree. The
standard approach for HDBSCAN* is to use an Excess of Mass ("eom")
algorithm to find the most persistent clusters. Alternatively you can
instead select the clusters at the leaves of the tree – this provides
the most fine grained and homogeneous clusters.
By default HDBSCAN* will not produce a single cluster, setting this to True will override this and allow single cluster results in the case that you feel this is a valid result for your dataset.
Which, if any, cluster centers to compute and store. The options are:
None which does not compute nor store any centers.
"centroid" which calculates the center by taking the weighted
average of their positions. Note that the algorithm uses the
euclidean metric and does not guarantee that the output will be
an observed data point.
"medoid" which calculates the center by taking the point in the
fitted data which minimizes the distance to all other points in
the cluster. This is slower than “centroid” since it requires
computing additional pairwise distances between points of the
same cluster but guarantees the output is an observed data point.
The medoid is also well-defined for arbitrary metrics, and does not
depend on a euclidean metric.
"both" which computes and stores both forms of centers.
If copy=True then any time an in-place modifications would be made
that would overwrite data passed to fit, a copy will first be
made, guaranteeing that the original data will be unchanged.
Currently, it only applies when metric="precomputed", when passing
a dense array or a CSR sparse matrix and when algorithm="brute".
Cluster labels for each point in the dataset given to fit. Outliers are labeled as follows:
Noisy samples are given the label -1.
Samples with infinite elements (+/- np.inf) are given the label -2.
Samples with missing data are given the label -3, even if they also have infinite elements.
The strength with which each sample is a member of its assigned cluster.
Clustered samples have probabilities proportional to the degree that they persist as part of the cluster.
Noisy samples have probability zero.
Samples with infinite elements (+/- np.inf) have probability 0.
Samples with missing data have probability np.nan.
The min_samples parameter includes the point itself, whereas the implementation in
scikit-learn-contrib/hdbscan
does not. To get the same results in both versions, the value of min_samples here
must be 1 greater than the value used in scikit-learn-contrib/hdbscan.
>>> import numpy as np
>>> from sklearn.cluster import HDBSCAN
>>> from sklearn.datasets import load_digits
>>> X, _ = load_digits(return_X_y=True)
>>> hdb = HDBSCAN(
Return clustering given by DBSCAN without border points.
Return clustering that would be equivalent to running DBSCAN* for a
particular cut_distance (or epsilon) DBSCAN* can be thought of as
DBSCAN without the border points. As such these results may differ
slightly from cluster.DBSCAN due to the difference in implementation
over the non-core points.
This can also be thought of as a flat clustering derived from constant height cut through the single linkage tree.
This represents the result of selecting a cut value for robust single linkage
clustering. The min_cluster_size allows the flat clustering to declare noise
points (and cluster smaller than min_cluster_size).
Find clusters based on hierarchical density-based clustering.
A feature array, or array of distances between samples if
metric='precomputed'.
Ignored.
Cluster X and return the associated cluster labels.
A feature array, or array of distances between samples if
metric='precomputed'.
Ignored.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
A MetadataRequest encapsulating
routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects
(such as Pipeline). The latter have
parameters of the form <component>__<parameter> so that it’s
possible to update each component of a nested object.
Estimator parameters.
Comparing different clustering algorithms on toy datasets
metric"brute"Number of features seen during fit.
n_features_in_,)Names of features seen during fit. Defined only when X
has feature names that are all strings.
A collection containing the centroid of each cluster calculated under the standard euclidean metric. The centroids may fall “outside” their respective clusters if the clusters themselves are non-convex.
Note that n_clusters only counts non-outlier clusters. That is to
say, the -1, -2, -3 labels for the outlier clusters are excluded.
A collection containing the medoid of each cluster calculated under
the whichever metric was passed to the metric parameter. The
medoids are points in the original cluster which minimize the average
distance to all other points in that cluster under the chosen metric.
These can be thought of as the result of projecting the metric-based
centroid back onto the cluster.
Note that n_clusters only counts non-outlier clusters. That is to
say, the -1, -2, -3 labels for the outlier clusters are excluded.
The mutual reachability distance cut value to use to generate a flat clustering.
Clusters smaller than this value with be called ‘noise’ and remain unclustered in the resulting flat clustering.
An array of cluster labels, one per datapoint. Outliers are labeled as follows:
Noisy samples are given the label -1.
Samples with infinite elements (+/- np.inf) are given the label -2.
Samples with missing data are given the label -3, even if they also have infinite elements.
Returns self.
Cluster labels.
Estimator instance.