Skip to content

Commit 1000000

Browse files
Charlie-XIAOpull[bot]
authored andcommitted
MAINT Parameters validation for sklearn.metrics.pairwise.laplacian_kernel (#26048)
1 parent b2e08cc commit 1000000

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

sklearn/metrics/pairwise.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from ..utils._mask import _get_mask
3030
from ..utils.parallel import delayed, Parallel
3131
from ..utils.fixes import sp_base_version, sp_version, parse_version
32-
from ..utils._param_validation import validate_params
32+
from ..utils._param_validation import validate_params, Interval, Real, Hidden
3333

3434
from ._pairwise_distances_reduction import ArgKmin
3535
from ._pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
@@ -1327,6 +1327,17 @@ def rbf_kernel(X, Y=None, gamma=None):
13271327
return K
13281328

13291329

1330+
@validate_params(
1331+
{
1332+
"X": ["array-like", "sparse matrix"],
1333+
"Y": ["array-like", "sparse matrix", None],
1334+
"gamma": [
1335+
Interval(Real, 0, None, closed="neither"),
1336+
Hidden(np.ndarray),
1337+
None,
1338+
],
1339+
}
1340+
)
13301341
def laplacian_kernel(X, Y=None, gamma=None):
13311342
"""Compute the laplacian kernel between X and Y.
13321343
@@ -1341,14 +1352,14 @@ def laplacian_kernel(X, Y=None, gamma=None):
13411352
13421353
Parameters
13431354
----------
1344-
X : ndarray of shape (n_samples_X, n_features)
1355+
X : {array-like, sparse matrix} of shape (n_samples_X, n_features)
13451356
A feature array.
13461357
1347-
Y : ndarray of shape (n_samples_Y, n_features), default=None
1358+
Y : {array-like, sparse matrix} of shape (n_samples_Y, n_features), default=None
13481359
An optional second feature array. If `None`, uses `Y=X`.
13491360
13501361
gamma : float, default=None
1351-
If None, defaults to 1.0 / n_features.
1362+
If None, defaults to 1.0 / n_features. Otherwise it should be strictly positive.
13521363
13531364
Returns
13541365
-------

sklearn/tests/test_public_functions.py

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def _check_function_param_validation(
202202
"sklearn.metrics.ndcg_score",
203203
"sklearn.metrics.pairwise.additive_chi2_kernel",
204204
"sklearn.metrics.pairwise.haversine_distances",
205+
"sklearn.metrics.pairwise.laplacian_kernel",
205206
"sklearn.metrics.precision_recall_curve",
206207
"sklearn.metrics.precision_recall_fscore_support",
207208
"sklearn.metrics.precision_score",

0 commit comments

Comments
 (0)