cosinesimilarity

It computes Cosine Similarity between two vectors or matrices of same length. If one of the inputs has one row and the other has 'm' rows, then similarity is computed between one row and every other row. The results of similarity range from -1 to 1 where -1 means both vectors are exactly opposite, 1 represents exactly the same and intermediate represents the similarity or dissimilarity and zero represents the orthogonality.

Syntax

Similarity = cosinesimilarity(X,Y)

Inputs

X
First input vector or matrix.
Type: double
Dimension: vector | matrix
Y
Second input vector or matrix.
Type: double
Dimension: vector | matrix

Outputs

Similarity
The similarity between two inputs.
Type: double
Dimension: vector | matrix

Example

Example of cosinesimilarity

x = [1, 2, 3];
y = [4, 5, 6];
similarity = cosinesimilarity(x, y);
> similarity
similarity = 0.974631846