sklearn.metrics.pairwise.cosine_similarity()

sklearn.metrics.pairwise.cosine_similarity

sklearn.metrics.pairwise.cosine_similarity(X, Y=None, dense_output=True) [source]

Compute cosine similarity between samples in X and Y.

Cosine similarity, or the cosine kernel, computes similarity as the normalized dot product of X and Y:

K(X, Y) = <X, Y> / (||X||*||Y||)

On L2-normalized data, this function is equivalent to linear_kernel.

Read more in the User Guide.

Parameters:

X : ndarray or sparse array, shape: (n_samples_X, n_features)

Input data.

Y : ndarray or sparse array, shape: (n_samples_Y, n_features)

Input data. If None, the output will be the pairwise similarities between all samples in X.

dense_output : boolean (optional), default True

Whether to return dense output even when the input is sparse. If False, the output is sparse if both input arrays are sparse.

New in version 0.17: parameter dense_output for dense output.

Returns:

kernel matrix : array

An array with shape (n_samples_X, n_samples_Y).

© 2007–2016 The scikit-learn developers
Licensed under the 3-clause BSD License.
http://scikit-learn.org/stable/modules/generated/sklearn.metrics.pairwise.cosine_similarity.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部