Skip to content

Commit bcfb2ec

Browse files
authored
Fix parameter setting on init in RSL
1 parent 886de0b commit bcfb2ec

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

hdbscan/robust_single_linkage_.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ class RobustSingleLinkage(BaseEstimator, ClusterMixin):
338338
metric parameter.
339339
If metric is "precomputed", X is assumed to be a distance matrix and
340340
must be square.
341+
342+
metric_params : dict, option (default={})
343+
Keyword parameter arguments for calling the metric (for example
344+
the p values if using the minkowski metric).
341345
342346
algorithm : string, optional (default='best')
343347
Exactly which algorithm to use; hdbscan has variants specialised
@@ -380,7 +384,7 @@ class RobustSingleLinkage(BaseEstimator, ClusterMixin):
380384

381385
def __init__(self, cut=0.4, k=5, alpha=1.4142135623730951, gamma=5,
382386
metric='euclidean', algorithm='best', core_dist_n_jobs=4,
383-
**kwargs):
387+
metric_params={}):
384388

385389
self.cut = cut
386390
self.k = k
@@ -389,10 +393,7 @@ def __init__(self, cut=0.4, k=5, alpha=1.4142135623730951, gamma=5,
389393
self.metric = metric
390394
self.algorithm = algorithm
391395
self.core_dist_n_jobs = core_dist_n_jobs
392-
393-
self._metric_kwargs = kwargs
394-
395-
self._cluster_hierarchy = None
396+
self.metric_params = metric_params
396397

397398
def fit(self, X, y=None):
398399
"""Perform robust single linkage clustering from features or
@@ -413,7 +414,7 @@ def fit(self, X, y=None):
413414
X = check_array(X, accept_sparse='csr')
414415

415416
kwargs = self.get_params()
416-
kwargs.update(self._metric_kwargs)
417+
kwargs.update(self.metric_params)
417418

418419
self.labels_, self._cluster_hierarchy = robust_single_linkage(
419420
X, **kwargs)
@@ -441,7 +442,7 @@ def fit_predict(self, X, y=None):
441442

442443
@property
443444
def cluster_hierarchy_(self):
444-
if self._cluster_hierarchy is not None:
445+
if hasattr(self, '_cluster_hierarchy'):
445446
return SingleLinkageTree(self._cluster_hierarchy)
446447
else:
447448
raise AttributeError('No single linkage tree was generated; try running fit'

0 commit comments

Comments
 (0)