Worked Example: Worked Mathematical Example: Cosine Similarity & L1/L2 Distance
Compute Cosine Similarity, angle θ°, L2 Euclidean distance, and L1 Manhattan distance.
- Specify the function parameters, matrix entries, or confusion matrix counts.
- Apply the closed-form or iterative formula: CosineSim = (u · v) / (||u||₂ × ||v||₂); L2_Dist = √Σ(u_i − v_i)²; L1_Dist = Σ|u_i − v_i|.
- Examine the primary result, error bounds, and 3 interactive SVG plots.
Result: Computes Cosine Similarity & L1/L2 Distance via CosineSim = (u · v) / (||u||₂ × ||v||₂); L2_Dist = √Σ(u_i − v_i)²; L1_Dist = Σ|u_i − v_i|.
Mathematics & Statistics · Machine Learning & Classification Metrics
Cosine Similarity, Angular Distance, Euclidean (L2) & Manhattan (L1) Distance Calculator: inputs, method, and how to read the result
Compute Cosine Similarity, angle θ°, L2 Euclidean distance, and L1 Manhattan distance.
Choose inputs for the case you are checking
The defaults are illustrative. Replace them with values for your case and keep the units shown beside each field.
- U1: Vector u component 1.
- U2: Vector u component 2.
- U3: Vector u component 3.
- V1: Vector v component 1.
What the calculation includes
With the default values shown, Cosine Similarity (cos θ) is 0.947 similarity. The calculation follows Cosine Similarity & L1/L2 Distance Formula; the formula and variable definitions above show how the inputs combine.
One-input check: With the other defaults held constant, changing U1 from 3 u₁ to 4 u₁ changes Cosine Similarity (cos θ) from 0.947 similarity to 0.97 similarity. This is a comparison inside the calculator's stated model, not a prediction.
Where to use caution
- Uses exact analytical or standard numerical analysis formulations from NIST DLMF.
- Double-precision floating-point arithmetic has ~15–17 significant decimal digits of precision.
Scope: Global Mathematical & Statistical Standard Check the assumptions and limitations against your situation before relying on the estimate.
More in Mathematics & Statistics: Scientific Calculator, Statistics & Standard Deviation Calculator, Permutations, Combinations, Probability, Sample Size & P-Value Calculator.