📐 Cosine Similarity Calculator
Calculate similarity between two vectors
Vector A
Vector B
How to Use This Calculator
Enter Vector Components
Input the x, y, and optionally z components for both vectors. Leave z components blank (or 0) for 2D vectors.
Click Calculate
Press "Calculate Cosine Similarity" to find the similarity between the two vectors.
View Results
See the cosine similarity (ranges from -1 to 1), angle between vectors, dot product, and vector magnitudes.
Formula
cosine similarity = (A · B) / (|A| × |B|)
where A · B is the dot product, |A| and |B| are vector magnitudes
Key Formulas:
- Dot product: A · B = A_xB_x + A_yB_y + A_zB_z
- Magnitude: |A| = √(A_x² + A_y² + A_z²)
- Cosine similarity = cos(θ), where θ is the angle between vectors
- Angle: θ = arccos(cosine similarity)
Interpretation:
- 1.0: Vectors point in the same direction (identical)
- 0.0: Vectors are perpendicular (orthogonal)
- -1.0: Vectors point in opposite directions
Example: A = (1, 2), B = (3, 4)
Dot product = 1×3 + 2×4 = 11
|A| = √(1² + 2²) = √5 ≈ 2.236
|B| = √(3² + 4²) = 5
Cosine similarity = 11 / (2.236 × 5) ≈ 0.9839
About Cosine Similarity Calculator
The Cosine Similarity Calculator measures the similarity between two vectors by calculating the cosine of the angle between them. It's widely used in machine learning, text analysis, and recommendation systems.
When to Use This Calculator
- Machine Learning: Measure similarity between feature vectors
- Text Analysis: Compare document vectors (TF-IDF, word embeddings)
- Recommendation Systems: Find similar users or items
- Image Processing: Compare image feature vectors
- Data Science: Cluster analysis and similarity metrics
- Vector Math: Understand angles and relationships between vectors
Why Use Our Calculator?
- ✅ Normalized Similarity: Returns values from -1 to 1, independent of vector magnitudes
- ✅ Angle Calculation: Shows the angle between vectors in degrees
- ✅ Comprehensive Results: Displays dot product and magnitudes
- ✅ 2D and 3D Support: Works with 2D and 3D vectors
- ✅ 100% Accurate: Precise mathematical calculations
- ✅ Completely Free: No registration required
Understanding Cosine Similarity
Cosine similarity measures orientation (direction) rather than magnitude. It's the cosine of the angle between two vectors, ranging from -1 (opposite direction) to 1 (same direction), with 0 indicating perpendicular vectors.
- Range: -1 ≤ cosine similarity ≤ 1
- Magnitude-independent: Only depends on direction, not length
- Same direction: Cosine similarity = 1 (angle = 0°)
- Perpendicular: Cosine similarity = 0 (angle = 90°)
- Opposite direction: Cosine similarity = -1 (angle = 180°)
- Used in high-dimensional spaces (text analysis, ML)
Real-World Applications
Search Engines: Cosine similarity compares query vectors with document vectors to rank search results by relevance.
Recommendation Systems: Netflix and Amazon use cosine similarity to find users with similar preferences or items with similar characteristics.
Document Similarity: Plagiarism detection and document clustering use cosine similarity to measure how similar two documents are based on their word frequencies.
Frequently Asked Questions
What is cosine similarity?
Cosine similarity is the cosine of the angle between two vectors. It measures how similar two vectors are in direction, regardless of their magnitudes. Formula: cos(θ) = (A · B) / (|A| × |B|).
What does cosine similarity range from?
Cosine similarity ranges from -1 to 1. 1 means identical direction (angle = 0°), 0 means perpendicular (angle = 90°), and -1 means opposite direction (angle = 180°).
Why use cosine similarity instead of distance?
Cosine similarity is magnitude-independent. It measures direction similarity, not magnitude. For example, (1,1) and (2,2) have cosine similarity = 1 (same direction) even though their magnitudes differ.
When is cosine similarity better than Euclidean distance?
When you care about direction/orientation more than magnitude, especially in high-dimensional spaces (text analysis, ML). Cosine similarity is also faster to compute for normalized vectors.
Can cosine similarity be negative?
Yes! Negative cosine similarity (between -1 and 0) means the vectors form an obtuse angle (90° < θ < 180°). This indicates the vectors point in somewhat opposite directions.
How is this used in machine learning?
Cosine similarity is used for: document similarity (TF-IDF vectors), recommendation systems (user/item vectors), clustering (finding similar groups), and feature comparison (image/text embeddings).
What's the difference from dot product?
Dot product depends on both magnitude and direction. Cosine similarity (normalized dot product) depends only on direction. For unit vectors, dot product equals cosine similarity.