@@ -2279,6 +2279,19 @@ def kernel_metrics():
2279
2279
}
2280
2280
2281
2281
2282
+ @validate_params (
2283
+ {
2284
+ "X" : ["array-like" , "sparse matrix" ],
2285
+ "Y" : ["array-like" , "sparse matrix" , None ],
2286
+ "metric" : [
2287
+ StrOptions (set (PAIRWISE_KERNEL_FUNCTIONS ) | {"precomputed" }),
2288
+ callable ,
2289
+ ],
2290
+ "filter_params" : ["boolean" ],
2291
+ "n_jobs" : [Integral , None ],
2292
+ },
2293
+ prefer_skip_nested_validation = True ,
2294
+ )
2282
2295
def pairwise_kernels (
2283
2296
X , Y = None , metric = "linear" , * , filter_params = False , n_jobs = None , ** kwds
2284
2297
):
@@ -2303,18 +2316,19 @@ def pairwise_kernels(
2303
2316
2304
2317
Parameters
2305
2318
----------
2306
- X : ndarray of shape (n_samples_X, n_samples_X) or (n_samples_X, n_features)
2319
+ X : {array-like, sparse matrix} of shape (n_samples_X, n_samples_X) or \
2320
+ (n_samples_X, n_features)
2307
2321
Array of pairwise kernels between samples, or a feature array.
2308
2322
The shape of the array should be (n_samples_X, n_samples_X) if
2309
2323
metric == "precomputed" and (n_samples_X, n_features) otherwise.
2310
2324
2311
- Y : ndarray of shape (n_samples_Y, n_features), default=None
2325
+ Y : {array-like, sparse matrix} of shape (n_samples_Y, n_features), default=None
2312
2326
A second feature array only if X has shape (n_samples_X, n_features).
2313
2327
2314
2328
metric : str or callable, default="linear"
2315
2329
The metric to use when calculating kernel between instances in a
2316
2330
feature array. If metric is a string, it must be one of the metrics
2317
- in pairwise.PAIRWISE_KERNEL_FUNCTIONS.
2331
+ in `` pairwise.PAIRWISE_KERNEL_FUNCTIONS`` .
2318
2332
If metric is "precomputed", X is assumed to be a kernel matrix.
2319
2333
Alternatively, if metric is a callable function, it is called on each
2320
2334
pair of instances (rows) and the resulting value recorded. The callable
@@ -2365,7 +2379,5 @@ def pairwise_kernels(
2365
2379
func = PAIRWISE_KERNEL_FUNCTIONS [metric ]
2366
2380
elif callable (metric ):
2367
2381
func = partial (_pairwise_callable , metric = metric , ** kwds )
2368
- else :
2369
- raise ValueError ("Unknown kernel %r" % metric )
2370
2382
2371
2383
return _parallel_pairwise (X , Y , func , n_jobs , ** kwds )
0 commit comments