37
37
from .plots import CondensedTree , SingleLinkageTree , MinimumSpanningTree
38
38
from .prediction import PredictionData
39
39
40
- FAST_METRICS = KDTree .valid_metrics + BallTree .valid_metrics + ["cosine" , "arccos" ]
40
+ KDTREE_VALID_METRICS = ["euclidean" , "l2" , "minkowski" , "p" , "manhattan" , "cityblock" , "l1" , "chebyshev" , "infinity" ]
41
+ BALLTREE_VALID_METRICS = KDTREE_VALID_METRICS + [
42
+ "braycurtis" ,
43
+ "canberra" ,
44
+ "dice" ,
45
+ "hamming" ,
46
+ "haversine" ,
47
+ "jaccard" ,
48
+ "mahalanobis" ,
49
+ "rogerstanimoto" ,
50
+ "russellrao" ,
51
+ "seuclidean" ,
52
+ "sokalmichener" ,
53
+ "sokalsneath" ,
54
+ ]
55
+ FAST_METRICS = KDTREE_VALID_METRICS + BALLTREE_VALID_METRICS + ["cosine" , "arccos" ]
41
56
42
57
# Author: Leland McInnes <leland.mcinnes@gmail.com>
43
58
# Steve Astels <sastels@gmail.com>
@@ -742,19 +757,19 @@ def hdbscan(
742
757
_hdbscan_generic
743
758
)(X , min_samples , alpha , metric , p , leaf_size , gen_min_span_tree , ** kwargs )
744
759
elif algorithm == "prims_kdtree" :
745
- if metric not in KDTree . valid_metrics :
760
+ if metric not in KDTREE_VALID_METRICS :
746
761
raise ValueError ("Cannot use Prim's with KDTree for this" " metric!" )
747
762
(single_linkage_tree , result_min_span_tree ) = memory .cache (
748
763
_hdbscan_prims_kdtree
749
764
)(X , min_samples , alpha , metric , p , leaf_size , gen_min_span_tree , ** kwargs )
750
765
elif algorithm == "prims_balltree" :
751
- if metric not in BallTree . valid_metrics :
766
+ if metric not in BALLTREE_VALID_METRICS :
752
767
raise ValueError ("Cannot use Prim's with BallTree for this" " metric!" )
753
768
(single_linkage_tree , result_min_span_tree ) = memory .cache (
754
769
_hdbscan_prims_balltree
755
770
)(X , min_samples , alpha , metric , p , leaf_size , gen_min_span_tree , ** kwargs )
756
771
elif algorithm == "boruvka_kdtree" :
757
- if metric not in BallTree . valid_metrics :
772
+ if metric not in BALLTREE_VALID_METRICS :
758
773
raise ValueError ("Cannot use Boruvka with KDTree for this" " metric!" )
759
774
(single_linkage_tree , result_min_span_tree ) = memory .cache (
760
775
_hdbscan_boruvka_kdtree
@@ -771,7 +786,7 @@ def hdbscan(
771
786
** kwargs
772
787
)
773
788
elif algorithm == "boruvka_balltree" :
774
- if metric not in BallTree . valid_metrics :
789
+ if metric not in BALLTREE_VALID_METRICS :
775
790
raise ValueError ("Cannot use Boruvka with BallTree for this" " metric!" )
776
791
if (X .shape [0 ] // leaf_size ) > 16000 :
777
792
warn (
@@ -802,7 +817,7 @@ def hdbscan(
802
817
(single_linkage_tree , result_min_span_tree ) = memory .cache (
803
818
_hdbscan_generic
804
819
)(X , min_samples , alpha , metric , p , leaf_size , gen_min_span_tree , ** kwargs )
805
- elif metric in KDTree . valid_metrics :
820
+ elif metric in KDTREE_VALID_METRICS :
806
821
# TO DO: Need heuristic to decide when to go to boruvka;
807
822
# still debugging for now
808
823
if X .shape [1 ] > 60 :
@@ -1237,9 +1252,9 @@ def generate_prediction_data(self):
1237
1252
1238
1253
if self .metric in FAST_METRICS :
1239
1254
min_samples = self .min_samples or self .min_cluster_size
1240
- if self .metric in KDTree . valid_metrics :
1255
+ if self .metric in KDTREE_VALID_METRICS :
1241
1256
tree_type = "kdtree"
1242
- elif self .metric in BallTree . valid_metrics :
1257
+ elif self .metric in BALLTREE_VALID_METRICS :
1243
1258
tree_type = "balltree"
1244
1259
else :
1245
1260
warn ("Metric {} not supported for prediction data!" .format (self .metric ))
0 commit comments