Skip to content

Commit be742c3

Browse files
qinhanmin2014jnothman
authored andcommitted
MNT Change default metric in OPTICS (scikit-learn#12439)
1 parent b498ac7 commit be742c3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

sklearn/cluster/optics_.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from ..metrics import pairwise_distances
2323

2424

25-
def optics(X, min_samples=5, max_eps=np.inf, metric='euclidean',
25+
def optics(X, min_samples=5, max_eps=np.inf, metric='minkowski',
2626
p=2, metric_params=None, maxima_ratio=.75,
2727
rejection_ratio=.7, similarity_threshold=0.4,
2828
significant_min=.003, min_cluster_size=.005,
@@ -60,7 +60,7 @@ def optics(X, min_samples=5, max_eps=np.inf, metric='euclidean',
6060
clusters across all scales; reducing `max_eps` will result in
6161
shorter run times.
6262
63-
metric : string or callable, optional (default='euclidean')
63+
metric : string or callable, optional (default='minkowski')
6464
metric to use for distance computation. Any metric from scikit-learn
6565
or scipy.spatial.distance can be used.
6666
@@ -215,7 +215,7 @@ class OPTICS(BaseEstimator, ClusterMixin):
215215
clusters across all scales; reducing `max_eps` will result in
216216
shorter run times.
217217
218-
metric : string or callable, optional (default='euclidean')
218+
metric : string or callable, optional (default='minkowski')
219219
metric to use for distance computation. Any metric from scikit-learn
220220
or scipy.spatial.distance can be used.
221221
@@ -353,7 +353,7 @@ class OPTICS(BaseEstimator, ClusterMixin):
353353
the Conference "Lernen, Wissen, Daten, Analysen" (LWDA) (2018): 318-329.
354354
"""
355355

356-
def __init__(self, min_samples=5, max_eps=np.inf, metric='euclidean',
356+
def __init__(self, min_samples=5, max_eps=np.inf, metric='minkowski',
357357
p=2, metric_params=None, maxima_ratio=.75,
358358
rejection_ratio=.7, similarity_threshold=0.4,
359359
significant_min=.003, min_cluster_size=.005,

sklearn/cluster/tests/test_optics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_correct_number_of_clusters():
3939
X = generate_clustered_data(n_clusters=n_clusters)
4040
# Parameters chosen specifically for this task.
4141
# Compute OPTICS
42-
clust = OPTICS(max_eps=5.0 * 6.0, min_samples=4, metric='euclidean')
42+
clust = OPTICS(max_eps=5.0 * 6.0, min_samples=4)
4343
clust.fit(X)
4444
# number of clusters, ignoring noise if present
4545
n_clusters_1 = len(set(clust.labels_)) - int(-1 in clust.labels_)
@@ -366,7 +366,7 @@ def test_compare_to_ELKI():
366366
# Tests against known extraction array
367367
# Does NOT work with metric='euclidean', because sklearn euclidean has
368368
# worse numeric precision. 'minkowski' is slower but more accurate.
369-
clust = OPTICS(min_samples=5, metric='minkowski').fit(X)
369+
clust = OPTICS(min_samples=5).fit(X)
370370

371371
assert_array_equal(clust.ordering_, np.array(o))
372372
assert_array_equal(clust.predecessor_[clust.ordering_], np.array(p))

0 commit comments

Comments
 (0)