8000 DOC Mention of pairwise_distances in Guide on Metrics (#12416) · lithuak/scikit-learn@a1fabce · GitHub
[go: up one dir, main page]

Skip to content

Commit a1fabce

Browse files
daten-kiekerqinhanmin2014
authored andcommitted
DOC Mention of pairwise_distances in Guide on Metrics (scikit-learn#12416)
1 parent f6b0c67 commit a1fabce

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doc/modules/metrics.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ the kernel:
3333
2. ``S = 1. / (D / np.max(D))``
3434

3535

36+
.. currentmodule:: sklearn.metrics
37+
38+
The distances between the row vectors of ``X`` and the row vectors of ``Y``
39+
can be evaluated using :func:`pairwise_distances`. If ``Y`` is omitted the
40+
pairwise distances of the row vectors of ``X`` are calculated. Similarly,
41+
:func:`pairwise.pairwise_kernels` can be used to calculate the kernel between `X`
42+
and `Y` using different kernel functions. See the API reference for more
43+
details.
44+
45+
>>> import numpy as np
46+
>>> from sklearn.metrics import pairwise_distances
47+
>>> from sklearn.metrics.pairwise import pairwise_kernels
48+
>>> X = np.array([[2, 3], [3, 5], [5, 8]])
49+
>>> Y = np.array([[1, 0], [2, 1]])
50+
>>> pairwise_distances(X, Y, metric='manhattan')
51+
array([[ 4., 2.],
52+
[ 7., 5.],
53+
[12., 10.]])
54+
>>> pairwise_distances(X, metric='manhattan')
55+
array([[0., 3., 8.],
56+
[3., 0., 5.],
57+
[8., 5., 0.]])
58+
>>> pairwise_kernels(X, Y, metric='linear')
59+
array([[ 2., 7.],
60+
[ 3., 11.],
61+
[ 5., 18.]])
62+
63+
3664
.. currentmodule:: sklearn.metrics.pairwise
3765

3866
.. _cosine_similarity:

0 commit comments

Comments
 (0)
0