Skip to content

MAINT Parameters validation for sklearn.metrics.pairwise.laplacian_kernel #26048

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 15 additions & 4 deletions sklearn/metrics/pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from ..utils._mask import _get_mask
from ..utils.parallel import delayed, Parallel
from ..utils.fixes import sp_base_version, sp_version, parse_version
from ..utils._param_validation import validate_params
from ..utils._param_validation import validate_params, Interval, Real, Hidden

from ._pairwise_distances_reduction import ArgKmin
from ._pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
Expand Down Expand Up @@ -1327,6 +1327,17 @@ def rbf_kernel(X, Y=None, gamma=None):
return K


@validate_params(
{
"X": ["array-like", "sparse matrix"],
"Y": ["array-like", "sparse matrix", None],
"gamma": [
Interval(Real, 0, None, closed="neither"),
Hidden(np.ndarray),
None,
],
}
)
def laplacian_kernel(X, Y=None, gamma=None):
"""Compute the laplacian kernel between X and Y.

Expand All @@ -1341,14 +1352,14 @@ def laplacian_kernel(X, Y=None, gamma=None):

Parameters
----------
X : ndarray of shape (n_samples_X, n_features)
X : {array-like, sparse matrix} of shape (n_samples_X, n_features)
A feature array.

Y : ndarray of shape (n_samples_Y, n_features), default=None
Y : {array-like, sparse matrix} of shape (n_samples_Y, n_features), default=None
An optional second feature array. If `None`, uses `Y=X`.

gamma : float, default=None
If None, defaults to 1.0 / n_features.
If None, defaults to 1.0 / n_features. Otherwise it should be strictly positive.

Returns
-------
Expand Down
1 change: 1 addition & 0 deletions sklearn/tests/test_public_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def _check_function_param_validation(
"sklearn.metrics.ndcg_score",
"sklearn.metrics.pairwise.additive_chi2_kernel",
"sklearn.metrics.pairwise.haversine_distances",
"sklearn.metrics.pairwise.laplacian_kernel",
"sklearn.metrics.precision_recall_curve",
"sklearn.metrics.precision_recall_fscore_support",
"sklearn.metrics.precision_score",
Expand Down