@@ -52,11 +52,30 @@ def optics(X, min_samples=5, max_eps=np.inf, metric='euclidean',
52
52
shorter run times.
53
53
54
54
metric : string or callable, optional (default='euclidean')
55
- The distance metric to use for neighborhood lookups. Default is
56
- "euclidean". Other options include "minkowski", "manhattan",
57
- "chebyshev", "haversine", "seuclidean", "hamming", "canberra",
58
- and "braycurtis". The "wminkowski" and "mahalanobis" metrics are
59
- also valid with an additional argument.
55
+ metric to use for distance computation. Any metric from scikit-learn
56
+ or scipy.spatial.distance can be used.
57
+
58
+ If metric is a callable function, it is called on each
59
+ pair of instances (rows) and the resulting value recorded. The callable
60
+ should take two arrays as input and return one value indicating the
61
+ distance between them. This works for Scipy's metrics, but is less
62
+ efficient than passing the metric name as a string.
63
+
64
+ Distance matrices are not supported.
65
+
66
+ Valid values for metric are:
67
+
68
+ - from scikit-learn: ['cityblock', 'cosine', 'euclidean', 'l1', 'l2',
69
+ 'manhattan']
70
+
71
+ - from scipy.spatial.distance: ['braycurtis', 'canberra', 'chebyshev',
72
+ 'correlation', 'dice', 'hamming', 'jaccard', 'kulsinski',
73
+ 'mahalanobis', 'minkowski', 'rogerstanimoto', 'russellrao',
74
+ 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean',
75
+ 'yule']
76
+
77
+ See the documentation for scipy.spatial.distance for details on these
78
+ metrics.
60
79
61
80
p : integer, optional (default=2)
62
81
Parameter for the Minkowski metric from
@@ -182,11 +201,30 @@ class OPTICS(BaseEstimator, ClusterMixin):
182
201
shorter run times.
183
202
184
203
metric : string or callable, optional (default='euclidean')
185
- The distance metric to use for neighborhood lookups. Default is
186
8000
- "euclidean". Other options include "minkowski", "manhattan",
187
- "chebyshev", "haversine", "seuclidean", "hamming", "canberra",
188
- and "braycurtis". The "wminkowski" and "mahalanobis" metrics are
189
- also valid with an additional argument.
204
+ metric to use for distance computation. Any metric from scikit-learn
205
+ or scipy.spatial.distance can be used.
206
+
207
+ If metric is a callable function, it is called on each
208
+ pair of instances (rows) and the resulting value recorded. The callable
209
+ should take two arrays as input and return one value indicating the
210
+ distance between them. This works for Scipy's metrics, but is less
211
+ efficient than passing the metric name as a string.
212
+
213
+ Distance matrices are not supported.
214
+
215
+ Valid values for metric are:
216
+
217
+ - from scikit-learn: ['cityblock', 'cosine', 'euclidean', 'l1', 'l2',
218
+ 'manhattan']
219
+
220
+ - from scipy.spatial.distance: ['braycurtis', 'canberra', 'chebyshev',
221
+ 'correlation', 'dice', 'hamming', 'jaccard', 'kulsinski',
222
+ 'mahalanobis', 'minkowski', 'rogerstanimoto', 'russellrao',
223
+ 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean',
224
+ 'yule']
225
+
226
+ See the documentation for scipy.spatial.distance for details on these
227
+ metrics.
190
228
191
229
p : integer, optional (default=2)
192
230
Parameter for the Minkowski metric from
@@ -419,8 +457,11 @@ def _set_reach_dist(self, point_index, processed, X, nbrs):
419
457
# Everything is already processed. Return to main loop
420
458
return point_index
421
459
422
- dists = pairwise_distances (P , np .take (X , unproc , axis = 0 ),
423
- self .metric , n_jobs = 1 ).ravel ()
460
+ if self .metric == 'precomputed' :
461
+ dists = X [point_index , unproc ]
462
+ else :
463
+ dists = pairwise_distances (P , np .take (X , unproc , axis = 0 ),
464
+ self .metric , n_jobs = None ).ravel ()
424
465
425
466
rdists = np .maximum (dists , self .core_distances_ [point_index ])
426
467
new_reach = np .minimum (np .take (self .reachability_ , unproc ), rdists )
0 commit comments