Cosine Similarity Calculator
Calculate cosine similarity, angle, and distance between vectors
Calculate Cosine Similarity
Both vectors will have the same dimension
Vector A = [a1, a2, a3]
Vector B = [b1, b2, b3]
Cosine Similarity Results
Formula: cos(θ) = (A⃗ · B⃗) / (||A⃗|| × ||B⃗||)
Dot Product (A⃗ · B⃗): 32.000000
Magnitude ||A⃗||: 3.741657
Magnitude ||B⃗||: 8.774964
Interpretation: Very similar vectors (same direction)
Step-by-Step Calculation
1. Calculate dot product: A⃗ · B⃗ = 1×4 + 2×5 + 3×6 = 32.000000
2. Calculate ||A⃗||: √(1² + 2² + 3²) = 3.741657
3. Calculate ||B⃗||: √(4² + 5² + 6²) = 8.774964
4. Cosine similarity: 32.000000 ÷ (3.741657 × 8.774964) = 0.974632
5. Angle: arccos(0.974632) = 12.93°
Similarity Analysis
Example: 2D Vector Similarity
Given Vectors
Vector A: [1, 5]
Vector B: [-1, 3]
Goal: Find cosine similarity and angle between vectors
Step-by-Step Solution
1. Dot product: A⃗ · B⃗ = (1)(-1) + (5)(3) = -1 + 15 = 14
2. Magnitude of A: ||A⃗|| = √(1² + 5²) = √26 ≈ 5.099
3. Magnitude of B: ||B⃗|| = √((-1)² + 3²) = √10 ≈ 3.162
4. Cosine similarity: 14 ÷ (5.099 × 3.162) ≈ 0.868
5. Result: cos(θ) = 0.868, θ ≈ 29.7°
Similarity Scale
Key Formulas
Cosine Similarity
cos(θ) = (A⃗ · B⃗) / (||A⃗|| × ||B⃗||)
Dot Product
A⃗ · B⃗ = Σ(aᵢ × bᵢ)
Vector Magnitude
||A⃗|| = √(Σaᵢ²)
Cosine Distance
D = 1 - cos(θ)
Understanding Cosine Similarity
What is Cosine Similarity?
Cosine similarity measures the cosine of the angle between two vectors, indicating their directional similarity regardless of magnitude. It's widely used in machine learning, natural language processing, and recommendation systems.
Key Properties
- •Range: [-1, 1] where 1 means identical direction, -1 means opposite
- •Independent of vector magnitude (only considers direction)
- •Undefined for zero vectors (magnitude = 0)
- •0 indicates orthogonal (perpendicular) vectors
Applications
Machine Learning
Document similarity, clustering, classification
Recommendation Systems
User preference similarity, item recommendations
Data Science
Feature correlation, dimensionality reduction
Text Analysis
Semantic similarity, information retrieval
Note: Cosine distance (1 - cosine similarity) is not a true metric as it doesn't satisfy the triangle inequality property.