sklearn.metrics.pairwise
.paired_cosine_distances¶
- sklearn.metrics.pairwise.paired_cosine_distances(X, Y)[source]¶
Compute the paired cosine distances between X and Y.
Read more in the User Guide.
- Parameters:
- X{array-like, sparse matrix} of shape (n_samples, n_features)
An array where each row is a sample and each column is a feature.
- Y{array-like, sparse matrix} of shape (n_samples, n_features)
An array where each row is a sample and each column is a feature.
- Returns:
- distancesndarray of shape (n_samples,)
Returns the distances between the row vectors of
X
and the row vectors ofY
, wheredistances[i]
is the distance betweenX[i]
andY[i]
.
Notes
The cosine distance is equivalent to the half the squared euclidean distance if each sample is normalized to unit norm.
Examples
>>> from sklearn.metrics.pairwise import paired_cosine_distances >>> X = [[0, 0, 0], [1, 1, 1]] >>> Y = [[1, 0, 0], [1, 1, 0]] >>> paired_cosine_distances(X, Y) array([0.5 , 0.18...])