Home Β» All Calculators Β» Mathematics and Statistics Β» Cosine Similarity Calculator

Cosine Similarity Calculator

Photo of author
Published on

Cosine similarity is a measure used to determine how similar two sets of data are. It is often used in various fields such as data analysis, machine learning, and information retrieval, especially in the context of text mining and document comparison. The cosine similarity calculator is a tool designed to compute this similarity measure between two vectors in a multidimensional space.

Understanding Cosine Similarity

Cosine similarity calculates the cosine of the angle between two vectors in an n-dimensional space. This angle represents the degree of similarity between the two vectors: the smaller the angle, the higher the similarity, with an angle of zero indicating identical vectors.


The formula for cosine similarity is: Cosine Similarity(𝐴,𝐡)=𝐴⋅𝐡βˆ₯𝐴βˆ₯βˆ₯𝐡βˆ₯Cosine Similarity(A,B)=βˆ₯Aβˆ₯βˆ₯Bβˆ₯Aβ‹…B​ Where:

  • 𝐴⋅𝐡Aβ‹…B is the dot product of vectors A and B.
  • βˆ₯𝐴βˆ₯βˆ₯Aβˆ₯ and βˆ₯𝐡βˆ₯βˆ₯Bβˆ₯ are the magnitudes (or norms) of vectors A and B.

Inputs Required

  1. Vector A Components: Numbers representing the vector A (e.g., [1, 2, 3]).
  2. Vector B Components: Numbers representing the vector B (e.g., [4, 5, 6]).

Step-by-Step Calculation Example

Let’s consider two vectors:

  • Vector A = [1, 2, 3]
  • Vector B = [4, 5, 6]

Calculate the Dot Product


Calculate the Magnitude of Each Vector

βˆ₯𝐴βˆ₯=12+22+32=1+4+9=14βˆ₯Aβˆ₯=12+22+32​=1+4+9​=14​ βˆ₯𝐡βˆ₯=42+52+62=16+25+36=77βˆ₯Bβˆ₯=42+52+62​=16+25+36​=77​

Compute the Cosine Similarity

Cosine Similarity=3214Γ—77β‰ˆ0.974Cosine Similarity=14​×77​32β€‹β‰ˆ0.974

This result of approximately 0.974 suggests that vectors A and B are very similar, as the cosine similarity is close to 1.

Relevant Information Table

VectorsLists of numbers representing directions and magnitudesA = [1, 2, 3], B = [4, 5, 6]
Dot ProductSum of products of corresponding entries from two vectors1Γ—4+2Γ—5+3Γ—6=321Γ—4+2Γ—5+3Γ—6=32
MagnitudeSquare root of the sum of squared components of a vector12+22+32=1412+22+32​=14​ for A
Cosine SimilarityCosine of the angle between two vectors, indicating similarity0.974 (near 1 indicates high similarity)


The Cosine Similarity Calculator is an invaluable tool for anyone needing to assess the similarity between two data sets or documents. By comparing the cosine of the angle between two vectors, it offers a clear, mathematical measure of how closely related two sets of data are. This is particularly useful in fields where pattern recognition, clustering, and document similarity are important. Whether for academic, professional, or casual use, understanding and applying cosine similarity can greatly enhance data analysis and decision-making processes.

Leave a Comment