New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MRG] Make OPTICS support sparse input #14736
Closed
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5f7e6de
Try csr support.
huntzhan 18425aa
Change the default metric of OPTICS to euclidean.
huntzhan f712b46
Retain the default metric minkowski.
huntzhan 876bb29
Undo tests.
huntzhan 71b5c1e
Fix flake8.
huntzhan 6f498a9
Add sparse tests.
huntzhan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,7 +194,7 @@ class OPTICS(BaseEstimator, ClusterMixin): | |
the Conference "Lernen, Wissen, Daten, Analysen" (LWDA) (2018): 318-329. | ||
""" | ||
|
||
def __init__(self, min_samples=5, max_eps=np.inf, metric='minkowski', p=2, | ||
def __init__(self, min_samples=5, max_eps=np.inf, metric='euclidean', p=2, | ||
metric_params=None, cluster_method='xi', eps=None, xi=0.05, | ||
predecessor_correction=True, min_cluster_size=None, | ||
algorithm='auto', leaf_size=30, n_jobs=None): | ||
|
@@ -233,7 +233,7 @@ def fit(self, X, y=None): | |
self : instance of OPTICS | ||
The instance. | ||
""" | ||
X = check_array(X, dtype=np.float) | ||
X = check_array(X, accept_sparse='csr') | ||
|
||
if self.cluster_method not in ['dbscan', 'xi']: | ||
raise ValueError("cluster_method should be one of" | ||
|
@@ -517,7 +517,7 @@ def _set_reach_dist(core_distances_, reachability_, predecessor_, | |
# the same logic as neighbors, p is ignored if explicitly set | ||
# in the dict params | ||
_params['p'] = p | ||
dists = pairwise_distances(P, np.take(X, unproc, axis=0), | ||
dists = pairwise_distances(P, X[unproc], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
metric, n_jobs=None, | ||
**_params).ravel() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default metric
minkowski
doesn't accept the sparse matrix.See https://github.com/huntzhan/scikit-learn/blob/5f7e6de69e425cfdfeeb82cf692b81fe22589dd5/sklearn/metrics/pairwise.py#L1546-L1555
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this won't work if the user changes
p
. So I'd rather reinterpret the metric as euclidean below when using the metric, rather than changing the defaultThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you able to add commits to resolve it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I will resolve this issue and add test cases this week.