|
20 | 20 | from ._dbscan_inner import dbscan_inner
|
21 | 21 |
|
22 | 22 |
|
23 |
| -def dbscan(X, eps=0.5, min_samples=5, metric='minkowski', |
| 23 | +def dbscan(X, eps=0.5, min_samples=5, metric='minkowski', metric_params=None, |
24 | 24 | algorithm='auto', leaf_size=30, p=2, sample_weight=None, n_jobs=1):
|
25 | 25 | """Perform DBSCAN clustering from vector array or distance matrix.
|
26 | 26 |
|
@@ -50,6 +50,11 @@ def dbscan(X, eps=0.5, min_samples=5, metric='minkowski',
|
50 | 50 | must be square. X may be a sparse matrix, in which case only "nonzero"
|
51 | 51 | elements may be considered neighbors for DBSCAN.
|
52 | 52 |
|
| 53 | + metric_params : dict, optional |
| 54 | + Additional keyword arguments for the metric function. |
| 55 | +
|
| 56 | + .. versionadded:: 0.19 |
| 57 | +
|
53 | 58 | algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, optional
|
54 | 59 | The algorithm to be used by the NearestNeighbors module
|
55 | 60 | to compute pointwise distances and find nearest neighbors.
|
@@ -130,7 +135,8 @@ def dbscan(X, eps=0.5, min_samples=5, metric='minkowski',
|
130 | 135 | else:
|
131 | 136 | neighbors_model = NearestNeighbors(radius=eps, algorithm=algorithm,
|
132 | 137 | leaf_size=leaf_size,
|
133 |
| - metric=metric, p=p, |
| 138 | + metric=metric, |
| 139 | + metric_params=metric_params, p=p, |
134 | 140 | n_jobs=n_jobs)
|
135 | 141 | neighbors_model.fit(X)
|
136 | 142 | # This has worst case O(n^2) memory complexity
|
@@ -184,6 +190,11 @@ class DBSCAN(BaseEstimator, ClusterMixin):
|
184 | 190 | .. versionadded:: 0.17
|
185 | 191 | metric *precomputed* to accept precomputed sparse matrix.
|
186 | 192 |
|
| 193 | + metric_params : dict, optional |
| 194 | + Additional keyword arguments for the metric function. |
| 195 | +
|
| 196 | + .. versionadded:: 0.19 |
| 197 | +
|
187 | 198 | algorithm : {'auto', 'ball_tree', 'kd_tree', 'brute'}, optional
|
188 | 199 | The algorithm to be used by the NearestNeighbors module
|
189 | 200 | to compute pointwise distances and find nearest neighbors.
|
@@ -237,10 +248,12 @@ class DBSCAN(BaseEstimator, ClusterMixin):
|
237 | 248 | """
|
238 | 249 |
|
239 | 250 | def __init__(self, eps=0.5, min_samples=5, metric='euclidean',
|
240 |
| - algorithm='auto', leaf_size=30, p=None, n_jobs=1): |
| 251 | + metric_params=None, algorithm='auto', leaf_size=30, p=None, |
| 252 | + n_jobs=1): |
241 | 253 | self.eps = eps
|
242 | 254 | self.min_samples = min_samples
|
243 | 255 | self.metric = metric
|
| 256 | + self.metric_params = metric_params |
244 | 257 | self.algorithm = algorithm
|
245 | 258 | self.leaf_size = leaf_size
|
246 | 259 | self.p = p
|
|
0 commit comments