[go: up one dir, main page]

Skip to content
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

MAINT Make ArgKminClassMode accept sparse datasets #27018

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Override valid_metrics over is_usable_for
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>

Co-authored-by: Meekail Zain <Micky774@users.noreply.github.com>
  • Loading branch information
jjerphan and Micky774 committed Aug 8, 2023
commit 876f21c30344cace1a058c02ad65f255f6a55010
34 changes: 8 additions & 26 deletions sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,32 +451,14 @@ class ArgKminClassMode(BaseDistancesReductionDispatcher):
"""

@classmethod
def is_usable_for(cls, X, Y, metric) -> bool:
"""Return True if the dispatcher can be used for the given parameters.

Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
The input array to be labelled.

Y : ndarray of shape (n_samples_Y, n_features)
The input array whose labels are provided through the `Y_labels`
parameter.

metric : str, default='euclidean'
The distance metric to use. For a list of available metrics, see
the documentation of :class:`~sklearn.metrics.DistanceMetric`.
Currently does not support `'precomputed'`.

Returns
-------
True if the PairwiseDistancesReduction can be used, else False.
"""
return (
ArgKmin.is_usable_for(X, Y, metric)
# TODO: implement Euclidean specialization with GEMM.
and metric not in ("euclidean", "sqeuclidean")
)
def valid_metrics(cls) -> List[str]:
excluded = {
# Euclidean is technically usable for ArgKminClassMode but it would not be competitive.
# TODO: implement Euclidean specialization using GEMM.
"euclidean"
"sqeuclidean",
}
return list(set(BaseDistancesReductionDispatcher.valid_metrics()) - excluded)

@classmethod
def compute(
Expand Down