diff --git a/doc/whats_new/v1.4.rst b/doc/whats_new/v1.4.rst index e168f1d667607..73b87d260acba 100644 --- a/doc/whats_new/v1.4.rst +++ b/doc/whats_new/v1.4.rst @@ -170,6 +170,11 @@ Changelog :mod:`sklearn.neighbors` ........................ +- |Efficiency| :meth:`sklearn.neighbors.KNeighborsRegressor.predict` and + :meth:`sklearn.neighbors.KNeighborsRegressor.predict_proba` now efficiently support + pairs of dense and sparse datasets. + :pr:`27018` by :user:`Julien Jerphanion `. + - |Fix| Neighbors based estimators now correctly work when `metric="minkowski"` and the metric parameter `p` is in the range `0 < p < 1`, regardless of the `dtype` of `X`. :pr:`26760` by :user:`Shreesha Kumar Bhat `. diff --git a/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py b/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py index e23da467d723a..937a6fd083260 100644 --- a/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py +++ b/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py @@ -451,35 +451,15 @@ 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: Support CSR matrices. - and not issparse(X) - and not issparse(Y) - # 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 its current implementation would not be competitive. + # TODO: implement Euclidean specialization using GEMM. + "euclidean", + "sqeuclidean", + } + return list(set(BaseDistancesReductionDispatcher.valid_metrics()) - excluded) @classmethod def compute(