How to convert Euclidean distance to range 0 and 1 like Cosine Similarity?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In machine learning and data analysis, similarity measures play a crucial role. Among these, Cosine Similarity is a popular choice for tasks like document comparison and clustering. It yields values between 0 and 1, where 1 indicates complete similarity and 0 no similarity, offering an intuitive understanding of how similar entities are. Conversely, Euclidean Distance, which measures the "straight-line" distance between two points in multi-dimensional space, yields a non-normalized distance value. This article explains how to scale Euclidean Distance into a range of [0, 1], allowing for a more direct comparison to similarity measures.
Understanding Euclidean Distance
Euclidean Distance, defined as:
calculates the geometric distance between two n-dimensional points and . While it's effective in capturing dissimilarities, its primary downside is its unbounded nature, potentially complicating interpretations across different datasets or feature scales.
Normalizing Euclidean Distance
To convert Euclidean Distance to a range [0, 1], akin to Cosine Similarity, normalization techniques are needed. Two primary methods for achieving this are Min-Max Normalization and the Exponential Transformation.
Min-Max Normalization
Min-Max Normalization rescales values linearly. For Euclidean Distance, the technique normalizes the distance using the formula:
Where: • is the raw Euclidean Distance. • is the maximum observed distance in the dataset or a theoretical maximum based on the context.
This approach yields a "distance similarity" value where 1 indicates identical points and 0 completely divergent points.
Example:
Assume three data points in 2D: • • •
Calculate all pairwise Euclidean Distances: • • •
Let the maximum observed distance .
Applying Min-Max Normalization: • • •
Exponential Transformation
Another effective transformation uses an exponential function, emphasizing smaller distances and compressing larger distances:
The exponential function inherently constrains the distance to [0, 1].
Example:
For the same points as above: • •
Exponential normalization: • • •
Comparison with Cosine Similarity
Here's a summary of converting Euclidean distances to a similarity-like measure alongside Cosine Similarity:
| Measure | Raw Value (Range) | Normalized (Range 0 to 1) |
| Euclidean Distance | $1 - \frac\{d(x, y)\}\{d_\{max\}\}$ or $e^\{-d(x, y)\}$ | |
| Cosine Similarity | mapping negative to zero (non-negative datasets) |
Cosine Similarity is direction-based, highlighting orientation over magnitude, and typically handles sparse data well. In contrast, normalized Euclidean Distance allows the consideration of absolute magnitudes.
Conclusion
Converting Euclidean Distance into a normalized, bounded similarity measure provides a clearer context for understanding data similarities. By applying methods such as Min-Max Normalization and Exponential Transformation, one can effectively translate raw Euclidean metrics into a range suitable for comparison with directional metrics like Cosine Similarity. This harmonizes inter-measure comparability and enhances interpretability in multi-modal data analyses.

