sklearn.metrics.pairwise.cosine_distances

sklearn.metrics.pairwise.cosine_distances(X, Y=None)[source]

Compute cosine distance between samples in X and Y.

Cosine distance is defined as 1.0 minus the cosine similarity.

Read more in the User Guide.

Parameters
Xarray_like, sparse matrix

with shape (n_samples_X, n_features).

Yarray_like, sparse matrix (optional)

with shape (n_samples_Y, n_features).

Returns
distance matrixarray

An array with shape (n_samples_X, n_samples_Y).