Cosine similarity
Cosine Similarity Cosine similarity measures the similarity between two vectors by calculating the dot product of the vectors and dividing it by the...
Cosine Similarity Cosine similarity measures the similarity between two vectors by calculating the dot product of the vectors and dividing it by the...
Cosine similarity measures the similarity between two vectors by calculating the dot product of the vectors and dividing it by the product of their magnitudes. The result tells you how similar the two vectors are in terms of their content.
Formally:
cos(θ) = (vector_a · vector_b) / (|vector_a| * |vector_b|)
where:
θ is the angle between the vectors
vector_a and vector_b are the two vectors
· denotes the dot product
|vector_a| and |vector_b| are the magnitudes of the vectors
Interpretation:
If θ is close to 0, it means the vectors are perpendicular, indicating no significant difference.
If θ is close to 1, it means the vectors are parallel, indicating a high degree of similarity.
A cos(θ) value of 0 indicates that the vectors are orthogonal, meaning they are perpendicular.
Examples:
Similarities:
Two vectors with the same direction will have a cos(θ) value close to 1.
Two vectors pointing in the same direction will have a cos(θ) value close to 1.
Differences:
Two vectors pointing in opposite directions will have a cos(θ) value close to -1.
Two vectors with no common direction will have a cos(θ) value close to 0.
Applications of Cosine Similarity:
Pattern Recognition: Cosine similarity can be used to find patterns in data by comparing vectors of different data points.
Image Similarity: Cosine similarity can be used to find images that are visually similar to each other.
Text Similarity: Cosine similarity can be used to find documents that are similar to a given document