`L i;UdZddlmZmZddlmZddlZddlm Z m Z ddl m Z m Z mZddlmZdd lmZdd lmZdd lmZmZmZdd lmZmZdd lmZmZmZddl m!Z!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(m)Z)m*Z*e+ejXejXzZ-ddddej\ddZ/e0e1d<dZ2dZ3 ddZ4 d dZ5dZ6dZ7Gdde e Z8y)!z\ HDBSCAN: Hierarchical Density-Based Spatial Clustering of Applications with Noise )IntegralReal)warnN)csgraphissparse) BaseEstimator ClusterMixin _fit_context)pairwise_distances)DistanceMetric)_VALID_METRICS)BallTreeKDTreeNearestNeighbors)Interval StrOptions)_allclose_dense_sparse_assert_all_finite validate_data)MST_edge_dtypemake_single_linkagemst_from_data_matrixmst_from_mutual_reachability)mutual_reachability_graph)HIERARCHY_dtypelabelling_at_cuttree_to_labels)labelprob)infinitemissing_OUTLIER_ENCODINGct|s t|S|j|jd}t fdt |Drt dddtj|dd}|dkDrt d |d tj|}|j\}}tjj|||jgt }|S) aJ Builds a minimum spanning tree (MST) from the provided mutual-reachability values. This function dispatches to a custom Cython implementation for dense arrays, and `scipy.sparse.csgraph.minimum_spanning_tree` for sparse arrays/matrices. Parameters ---------- mututal_reachability_graph: {ndarray, sparse matrix} of shape (n_samples, n_samples) Weighted adjacency matrix of the mutual reachability graph. min_samples : int, default=None The number of samples in a neighborhood for a point to be considered as a core point. This includes the point itself. Returns ------- mst : ndarray of shape (n_samples - 1,), dtype=MST_edge_dtype The MST representation of the mutual-reachability graph. The MST is represented as a collection of edges. rc3@K|]}|dz|z kyw)rN).0iindptr min_sampless f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/cluster/_hdbscan/hdbscan.py z_brute_mst..qs' PF1q5MF1I % 4 Psz$There exists points with fewer than zV neighbors. Ensure your distance matrix has non-zero values for at least `min_sample`=z neighbors for each points (i.e. K-nn graph), or specify a `max_distance` in `metric_params` to use when distances are missing.F)directed return_labelsrz&Sparse mutual reachability matrix has z connected components. HDBSCAN cannot be performed on a disconnected graph. Ensure that the sparse distance matrix has only one connected component.dtype)rrr,shapeanyrange ValueErrorrconnected_componentsminimum_spanning_treenonzeronprec fromarraysdatar) mutual_reachabilityr- num_points n_componentssparse_min_spanning_treerowscolsmstr,s ` @r. _brute_mstrFSs. ' (+,?@@! ' 'F$**1-J PeJ>O PP2;-@(M*& &  //e5La4\NCQ Q   '<<=PQ)113JD$ &&   t-223  C JcRtj|d}||}t|S)a8 Builds a single-linkage tree (SLT) from the provided minimum spanning tree (MST). The MST is first sorted then processed by a custom Cython routine. Parameters ---------- min_spanning_tree : ndarray of shape (n_samples - 1,), dtype=MST_edge_dtype The MST representation of the mutual-reachability graph. The MST is represented as a collection of edges. Returns ------- single_linkage : ndarray of shape (n_samples - 1,), dtype=HIERARCHY_dtype The single-linkage tree tree (dendrogram) built from the MST. distance)r;argsortr)min_spanning_tree row_orders r. _process_mstrMs/" ,Z89I))4 0 11rGc @|dk(rn|jd|jdk7rtd|jdt||js td|r|j n|}nt |f||d|}||z}|j dd }t|r|jd k7r|j}t||| } t| | } tj| d jrtdt t#| S)a Builds a single-linkage tree (SLT) from the input data `X`. If `metric="precomputed"` then `X` must be a symmetric array of distances. Otherwise, the pairwise distances are calculated directly and passed to `mutual_reachability_graph`. Parameters ---------- X : ndarray of shape (n_samples, n_features) or (n_samples, n_samples) Either the raw data from which to compute the pairwise distances, or the precomputed distances. min_samples : int, default=None The number of samples in a neighborhood for a point to be considered as a core point. This includes the point itself. alpha : float, default=1.0 A distance scaling parameter as used in robust single linkage. metric : str or callable, default='euclidean' 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 :func:`~sklearn.metrics.pairwise_distances` for its metric parameter. - If metric is "precomputed", X is assumed to be a distance matrix and must be square. n_jobs : int, default=None The number of jobs to use for computing the pairwise distances. This works by breaking down the pairwise matrix into n_jobs even slices and computing them in parallel. This parameter is passed directly to :func:`~sklearn.metrics.pairwise_distances`. ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. ``-1`` means using all processors. See :term:`Glossary ` for more details. copy : bool, default=False If `copy=True` then any time an in-place modifications would be made that would overwrite `X`, 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 array/matrix. metric_params : dict, default=None Arguments passed to the distance metric. Returns ------- single_linkage : ndarray of shape (n_samples - 1,), dtype=HIERARCHY_dtype The single-linkage tree tree (dendrogram) built from the MST. precomputedrrzRThe precomputed distance matrix is expected to be symmetric, however it has shape zC. Please verify that the distance matrix was constructed correctly.zThe precomputed distance matrix is expected to be symmetric, however its values appear to be asymmetric. Please verify that the distance matrix was constructed correctly.)metricn_jobs max_distancecsr)r-rR)r-rIzThe minimum spanning tree contains edge weights with value infinity. Potentially, you are missing too many distances in the initial distance matrix for the given neighborhood size.)r4r7rTcopyr getrformattocsrrrFr;isinfr5r UserWarningrM) Xr-alpharPrQrV metric_paramsdistance_matrixrRmutual_reachability_rKs r._hdbscan_bruteras>@ 771: #!!" *>>  &a-5  '+!&&(,  V /< uO $$^S9L _%;%;u%D*//15[|##7[Q xx!*-.224    ) **rGc 6tj|d}t||||||dj|}|j ||d\} } tj | dddf} t j|fi|} t|| | |} t| S)a Builds a single-linkage tree (SLT) from the input data `X`. If `metric="precomputed"` then `X` must be a symmetric array of distances. Otherwise, the pairwise distances are calculated directly and passed to `mutual_reachability_graph`. Parameters ---------- X : ndarray of shape (n_samples, n_features) The raw data. min_samples : int, default=None The number of samples in a neighborhood for a point to be considered as a core point. This includes the point itself. alpha : float, default=1.0 A distance scaling parameter as used in robust single linkage. metric : str or callable, default='euclidean' The metric to use when calculating distance between instances in a feature array. `metric` must be one of the options allowed by :func:`~sklearn.metrics.pairwise_distances` for its metric parameter. n_jobs : int, default=None The number of jobs to use for computing the pairwise distances. This works by breaking down the pairwise matrix into n_jobs even slices and computing them in parallel. This parameter is passed directly to :func:`~sklearn.metrics.pairwise_distances`. ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. ``-1`` means using all processors. See :term:`Glossary ` for more details. copy : bool, default=False If `copy=True` then any time an in-place modifications would be made that would overwrite `X`, 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 array/matrix. metric_params : dict, default=None Arguments passed to the distance metric. Returns ------- single_linkage : ndarray of shape (n_samples - 1,), dtype=HIERARCHY_dtype The single-linkage tree tree (dendrogram) built from the MST. C)orderN) n_neighbors algorithm leaf_sizerPr^rQpT)return_distance) r;asarrayrfit kneighborsascontiguousarrayr get_metricrrM)r\algor-r]rPrgrQr^nbrsneighbors_distances_core_distances dist_metricrKs r._hdbscan_primsrvsx 1C A #   c!f "__Q T_R))*=ae*DEN ++FDmDK-Q US ) **rGcrt|}t|}t|D]M\}}||d}||d}||kr ||||d<n ||z||d<||kr ||||d<C||z||d<Otjt|t} t ||j ddz d||j ddz d} ||j ddz d} t|D],\}} | | dztj| dzf| |<| dz } | dz } .tj|| g}|S)ay Takes an internal single_linkage_tree structure and adds back in a set of points that were initially detected as non-finite and returns that new tree. These points will all be merged into the final node at np.inf distance and considered noise points. Parameters ---------- tree : ndarray of shape (n_samples - 1,), dtype=HIERARCHY_dtype The single-linkage tree tree (dendrogram) built from the MST. internal_to_raw: dict A mapping from internal integer index to the raw integer index non_finite : ndarray Boolean array of which entries in the raw data are non-finite left_node right_noder2rr cluster_size) len enumerater;zerosrmaxr4inf concatenate) treeinternal_to_raw non_finite finite_count outlier_countr+rsleftright outlier_treelast_cluster_idlast_cluster_sizeoutliers r.remap_single_linkage_treerhs 'L OM$ :1Aw{#Q % , #24#8DGK #'-#7DGK < $3E$:DGL !$)M$9DGL ! :88C O?CL TZZ]Q  ,d4::a=13D.El.SOTZZ]Q./? + 7"Oa$7ARUVAVW Q1Q >>4. /D KrGc zt|rttjt|j j Dcgc]0\}}tj tj|s/|2c}}}|Stj|jdj\}|Scc}}w)z_ Returns the indices of the purely finite rows of a sparse matrix or dense ndarray raxis) rr;arrayr|tolilr>allisfinitesumr:)matrixr+row row_indicess r._get_finite_row_indicesrs hh&v||~':':; X61crvvbkkRUFV?WQ X VZZQZ%78@@B  Ys 0B7 2B7 ceZdZdZeedddgeeddddgeedddgdeedddgeee e zdhze ge dgeeddd gehd geedddgedged d hgd gdehdgd gdZ ddZedddZddZdZddZfdZxZS)HDBSCANa&Cluster data using hierarchical density-based clustering. HDBSCAN - Hierarchical Density-Based Spatial Clustering of Applications with Noise. Performs :class:`~sklearn.cluster.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 :class:`~sklearn.cluster.DBSCAN`), and be more robust to parameter selection. Read more in the :ref:`User Guide `. .. versionadded:: 1.3 Parameters ---------- min_cluster_size : int, default=5 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. min_samples : int, default=None 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`. cluster_selection_epsilon : float, default=0.0 A distance threshold. Clusters below this value will be merged. See [5]_ for more information. max_cluster_size : int, default=None 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"`. metric : str or callable, default='euclidean' 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 :func:`~sklearn.metrics.pairwise_distances` for its metric parameter. - If metric is "precomputed", X is assumed to be a distance matrix and must be square. metric_params : dict, default=None Arguments passed to the distance metric. alpha : float, default=1.0 A distance scaling parameter as used in robust single linkage. See [3]_ for more information. algorithm : {"auto", "brute", "kd_tree", "ball_tree"}, default="auto" Exactly which algorithm to use for computing core distances; By default this is set to `"auto"` which attempts to use a :class:`~sklearn.neighbors.KDTree` tree if possible, otherwise it uses a :class:`~sklearn.neighbors.BallTree` tree. Both `"kd_tree"` and `"ball_tree"` algorithms use the :class:`~sklearn.neighbors.NearestNeighbors` estimator. If the `X` passed during `fit` is sparse or `metric` is invalid for both :class:`~sklearn.neighbors.KDTree` and :class:`~sklearn.neighbors.BallTree`, then it resolves to use the `"brute"` algorithm. leaf_size : int, default=40 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"`. n_jobs : int, default=None Number of jobs to run in parallel to calculate distances. `None` means 1 unless in a :obj:`joblib.parallel_backend` context. `-1` means using all processors. See :term:`Glossary ` for more details. cluster_selection_method : {"eom", "leaf"}, default="eom" 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. allow_single_cluster : bool, default=False 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. store_centers : str, default=None 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. copy : bool, default=False If `copy=True` then any time an in-place modifications would be made that would overwrite data passed to :term:`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"`. Attributes ---------- labels_ : ndarray of shape (n_samples,) Cluster labels for each point in the dataset given to :term:`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. probabilities_ : ndarray of shape (n_samples,) 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`. n_features_in_ : int Number of features seen during :term:`fit`. feature_names_in_ : ndarray of shape (`n_features_in_`,) Names of features seen during :term:`fit`. Defined only when `X` has feature names that are all strings. centroids_ : ndarray of shape (n_clusters, n_features) 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. medoids_ : ndarray of shape (n_clusters, n_features) 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. See Also -------- DBSCAN : Density-Based Spatial Clustering of Applications with Noise. OPTICS : Ordering Points To Identify the Clustering Structure. Birch : Memory-efficient, online-learning algorithm. Notes ----- 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 `_. References ---------- .. [1] :doi:`Campello, R. J., Moulavi, D., & Sander, J. Density-based clustering based on hierarchical density estimates. <10.1007/978-3-642-37456-2_14>` .. [2] :doi:`Campello, R. J., Moulavi, D., Zimek, A., & Sander, J. Hierarchical density estimates for data clustering, visualization, and outlier detection.<10.1145/2733381>` .. [3] `Chaudhuri, K., & Dasgupta, S. Rates of convergence for the cluster tree. `_ .. [4] `Moulavi, D., Jaskowiak, P.A., Campello, R.J., Zimek, A. and Sander, J. Density-Based Clustering Validation. `_ .. [5] :arxiv:`Malzer, C., & Baum, M. "A Hybrid Approach To Hierarchical Density-based Cluster Selection."<1911.02282>`. Examples -------- >>> import numpy as np >>> from sklearn.cluster import HDBSCAN >>> from sklearn.datasets import load_digits >>> X, _ = load_digits(return_X_y=True) >>> hdb = HDBSCAN(min_cluster_size=20) >>> hdb.fit(X) HDBSCAN(min_cluster_size=20) >>> hdb.labels_.shape == (X.shape[0],) True >>> np.unique(hdb.labels_).tolist() [-1, 0, 1, 2, 3, 4, 5, 6, 7] Nr)rrclosedrrrOneither>autobrutekd_tree ball_treeeomleafboolean>bothmedoidcentroid)min_cluster_sizer-cluster_selection_epsilonmax_cluster_sizerPr^r]rfrgrQcluster_selection_methodallow_single_cluster store_centersrVFc||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ | |_ ||_ yN)rr-r]rrrPr^rfrgrQrrrrV)selfrr-rrrPr^r]rfrgrQrrrrVs r.__init__zHDBSCAN.__init__sn"!1& 0)B& *"" (@%$8!* rG)prefer_skip_nested_validationc  |jdk(r|j td|jxsi|_|jdk7rt ||ddgdt j}||_d} tt|r |jn||s|jd }t j|jd }t j|jd }t!|}t#|Dcic]\}}|| } }}||}nxt|r!t ||ddgt jd }nLt ||dt jd }t j|j%r td|j&d d k(r td|j( |j*n |j(|_|j,|j&d kDr)td|j,d|j&d dd} t/d$||j,|j0|j|j2d|j} |j4dk(r4|jt6j8vrt|jd|j4dk(r4|jt:j8vrt|jd|j4dk7r|jdk7r%t|r|j4dk7r td|j4dk(rt<} |j>| d<n|j4dk(rt@} d| d<|jB| d<nt@} d| d<|jB| d<nt|s|jtDvrt<} |j>| d<nQ|jt6j8vrt@} d| d<|jB| d<nt@} d| d<|jB| d<| d$i| |_#tI|jF|j*|jJ|jL|jN|jP\|_)|_*|jdk7rstW|jF tYt jZg|_#t j\|jj&d t j^} |jR| <t`d d!| |<t`d"d!| |<| |_)t jb|jj&d t j} |jT| |<t`d d#| |<t`d"d#| |<| |_*|jr|je||S#t$rd}YPwxYwcc}}w)%aFind clusters based on hierarchical density-based clustering. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features), or ndarray of shape (n_samples, n_samples) A feature array, or array of distances between samples if `metric='precomputed'`. y : None Ignored. Returns ------- self : object Returns self. rONz>Cannot store centers when using a precomputed distance matrix.rTlilF) accept_sparseensure_all_finiter3Trrr)rr3force_writeable)rr3rz(np.nan values found in precomputed-densez7n_samples=1 while HDBSCAN requires more than one samplez min_samples (z.) must be at most the number of samples in X ())r\r-r]rPrQrzV is not a valid metric for a KDTree-based algorithm. Please select a different metric.rzX is not a valid metric for a BallTree-based algorithm. Please select a different metric.rrz4Sparse data matrices only support algorithm `brute`.rVrprg)rr2r$r!r%r"r))3rPrr7r^_metric_paramsrr;float64 _raw_datarrr>risnanr:rZrr|r5r4r-r _min_samplesdictr]rQrfr valid_metricsrrarVrvrg FAST_METRICS_single_linkage_tree_rrrrrlabels_probabilities_rsethstackemptyint32r&r}_weighted_cluster_center)rr\y all_finite reduced_X missing_indexinfinite_index finite_indexxrmst_funckwargs new_labelsnew_probabilitiess r.rlz HDBSCAN.fits|, ;;- 'D,>,>,JP #006B ;;- '$en"'jj ADNJ #"Xa[166a@EEqEM !# 3 ; ; =a @ "$)!4!q!A 7q9 4=l4K"LDAq1a4"L"LlO a[$enjj $ Aa5 TXAxx{ !!KLL 771:?VW W%)%5%5%=D ! !4CSCS    qwwqz ) 1 123""#''!*Q0   ))**;;;;  !!   >>Y &4;;f>R>R+R;;- 55  NNk )dkkAWAW.W;;- 55  >>V # },QKNNg- !WXX~~()!%v9,)!*v&*nn{#)!,v&*nn{#{dkk=)!%v 4 44)!*v&*nn{#*!,v&*nn{#%-%7%7",:  & &  ! !  ) )  % %  * *  ! ! - ) d) ;;- ' *C**ryy.-)HIJ *D & $.."6"6q"9JJ'+||J| $)::)Fw)OJ~ &(9)(DW(MJ} %%DL ")=)=a)@ S .2.A.A l +1B*0Mf0U n -/@/KF/S m ,"3D      ) )! , m #"  #*#Ms5"W W+ W('W(c<|j||jS)aCluster X and return the associated cluster labels. Parameters ---------- X : {array-like, sparse matrix} of shape (n_samples, n_features), or ndarray of shape (n_samples, n_samples) A feature array, or array of distances between samples if `metric='precomputed'`. y : None Ignored. Returns ------- y : ndarray of shape (n_samples,) Cluster labels. )rlr)rr\rs r. fit_predictzHDBSCAN.fit_predictrs$  ||rGcJtt|jddhz }tj|j dftj }|jdv}|jdv}|r9tj||j dftj|_ |r9tj||j dftj|_ t|D]}|j|k(}||}|j|}|r%tj||d|j|<|sPt|fd |ji|j } | |z} tj"| j%d } || |j|<y ) a8Calculate and store the centroids/medoids of each cluster. This requires `X` to be a raw feature array, not precomputed distances. Rather than return outputs directly, this helper method instead stores them in the `self.{centroids, medoids}_` attributes. The choice for which attributes are calculated and stored is mediated by the value of `self.store_centers`. Parameters ---------- X : ndarray of shape (n_samples, n_features) The feature array that the estimator was fit with. rjr rr2)rr)rrr)weightsrrPrN)r{rrr;rr4bool_rr centroids_medoids_r6raverager rPrargminr) rr\ n_clustersmaskmake_centroids make_medoidsidxr>strengthdist_mat medoid_indexs r.rz HDBSCAN._weighted_cluster_centersn T\\*b"X56 xx RXX6++/CC))-??  hh AGGAJ'?rzzRDO HHj!''!*%=RZZPDM$ 8C<<3&DT7D**40H')zz$q'Q$-!%040C0C$h.!yy1)=> %),%7 c" 8 rGct|j||}|jtddk(}|jtddk(}tdd||<tdd||<|S)aReturn 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`). Parameters ---------- cut_distance : float The mutual reachability distance cut value to use to generate a flat clustering. min_cluster_size : int, default=5 Clusters smaller than this value with be called 'noise' and remain unclustered in the resulting flat clustering. Returns ------- labels : ndarray of shape (n_samples,) 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. r$r!r%)rrrr&)r cut_distancerlabelsrrs r.dbscan_clusteringzHDBSCAN.dbscan_clusteringsJ"  & & 6F )::)Fw)OO (9)(DW(MM "3:!>w!G~ 1) r sD#*==)3.;;;  5DD6''(*@*@@A   4":z22     l+d  O+d*Z E lME rG