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.
Input data.
Input data. If None
, the output will be the pairwise similarities between all samples in X
.
Whether to return dense output even when the input is sparse. If False
, the output is sparse if both input arrays are sparse.
Added in version 0.17: parameter dense_output
for dense output.
Returns the cosine similarity between samples in X and Y.
Examples
>>> from sklearn.metrics.pairwise import cosine_similarity >>> X = [[0, 0, 0], [1, 1, 1]] >>> Y = [[1, 0, 0], [1, 1, 0]] >>> cosine_similarity(X, Y) array([[0. , 0. ], [0.577, 0.816]])
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4