Skip to content

Commit ed590c5

Browse files
authored
DOC Improve pairwise_kernel docstring (scikit-learn#31103)
1 parent 4247273 commit ed590c5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

sklearn/metrics/pairwise.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,17 +2575,23 @@ def pairwise_kernels(
25752575
):
25762576
"""Compute the kernel between arrays X and optional array Y.
25772577
2578-
This method takes either a vector array or a kernel matrix, and returns
2579-
a kernel matrix. If the input is a vector array, the kernels are
2580-
computed. If the input is a kernel matrix, it is returned instead.
2578+
This method takes one or two vector arrays or a kernel matrix, and returns
2579+
a kernel matrix.
2580+
2581+
- If `X` is a vector array, of shape (n_samples_X, n_features), and:
2582+
2583+
- `Y` is `None` and `metric` is not 'precomputed', the pairwise kernels
2584+
between `X` and itself are computed.
2585+
- `Y` is a vector array of shape (n_samples_Y, n_features), the pairwise
2586+
kernels between arrays `X` and `Y` is returned.
2587+
2588+
- If `X` is a kernel matrix, of shape (n_samples_X, n_samples_X), `metric`
2589+
should be 'precomputed'. `Y` is thus ignored and `X` is returned as is.
25812590
25822591
This method provides a safe way to take a kernel matrix as input, while
25832592
preserving compatibility with many other algorithms that take a vector
25842593
array.
25852594
2586-
If Y is given (default is None), then the returned matrix is the pairwise
2587-
kernel between the arrays from both X and Y.
2588-
25892595
Valid values for metric are:
25902596
['additive_chi2', 'chi2', 'linear', 'poly', 'polynomial', 'rbf',
25912597
'laplacian', 'sigmoid', 'cosine']

0 commit comments

Comments
 (0)