Formula used
cosine similarity = (A · B) / (||A|| × ||B||)A · B = Σ(Aᵢ × Bᵢ)weighted cosine = Σ(wᵢAᵢBᵢ) / √Σ(wᵢAᵢ²)√Σ(wᵢBᵢ²)How to use
- Select vector, text, batch, or matrix mode.
- Enter dense values or sparse feature pairs.
- Choose weighting and preprocessing options.
- Set precision, thresholds, and ranking limits.
- Calculate, inspect steps, then export results.
Example data
| Case | Vector A | Vector B | Expected meaning |
|---|---|---|---|
| Identical | 1, 2, 3 | 1, 2, 3 | Similarity equals 1. |
| Scaled | 1, 2, 3 | 2, 4, 6 | Direction remains identical. |
| Orthogonal | 1, 0 | 0, 1 | Similarity equals 0. |
| Opposite | 1, 2 | -1, -2 | Similarity equals -1. |
Machine learning applications
Frequently asked questions
What does cosine similarity measure?
It measures directional agreement between two numeric vectors.
What range can the score use?
Scores range from negative one through positive one.
Why can scaled vectors score one?
Scaling changes magnitude but preserves the vector direction.
What happens with a zero vector?
Its direction is undefined, so similarity cannot calculate.
How does cosine distance work?
This calculator uses one minus the displayed similarity.
When should TF-IDF be selected?
Use TF-IDF when uncommon terms should receive more importance.
What is weighted cosine similarity?
It assigns different importance to individual vector features.
Does L2 normalisation change cosine similarity?
Usually no, but it exposes comparable normalised vector values.
How is cosine different from correlation?
Correlation centres values, while standard cosine does not.