Welcome to our Support Center

CosineSimilarity

Description

Computes the cosine similarity between the labels and predictions. Type : polymorphic.

 

 

Input parameters

 

 y_pred : array, predicted values. 
 y_true : array, true values.

 

Output parameters

 

cosine_similarity : float, result.

Use cases

The cosine similarity measure is commonly used in automatic natural language processing (NLP), text analysis, system recommendation and bioinformatics.

Here are a few specific areas of application:

    • In natural language processing (NLP) : cosine similarity is often used to compare the similarity between two documents or two words. For example, it can be used to measure the similarity between two sentences, or to find the most similar words to a given word in a vector space.
    • In recommendation systems : cosine similarity can be used to recommend similar products to a user based on their past preferences. For example, if a user has enjoyed certain films, you can recommend other similar films by calculating the cosine similarity between the vectors representing the films.
    • Bioinformatics : cosine similarity can be used to compare DNA or protein sequences.

It should be noted that while cosine similarity is a useful measure in many cases, it may not be appropriate in all scenarios, particularly where the absolute “distance” between vectors is large.

Calculation

Cosine similarity is a measure used to determine the degree of similarity between two vectors. It stores the average cosine similarity between predictions and labels in a data.

Cosine similarity gives a value between -1 and 1. A value of 1 means that the two vectors have the same orientation (are perfectly aligned), a value of -1 means that they have opposite orientations, and a value of 0 means that the vectors are orthogonal (perpendicular to each other). It is important to note that cosine similarity only takes into account the orientation of the vectors, not their length.

 

Example

All these exemples are snippets PNG, you can drop these Snippet onto the block diagram and get the depicted code added to your VI (Do not forget to install HAIBAL library to run it).

Easy to use

Table of Contents