Why Euclidean Distance Matters
Clustering methods use a notion of similarity to determine which observations are close to one another. For numeric predictors, a common choice is Euclidean distance: the straight-line distance between two points represented by their predictor values. A small distance indicates that the observations are close in the chosen coordinate system; a large distance indicates they are farther apart.
The calculation is straightforward, but its geometry matters. Each predictor contributes a squared difference, and those contributions add before taking a square root. As a result, a large difference on one coordinate can dominate the total, while several moderate differences can together produce a substantial distance. The earlier material on scaling predictors is important here: Euclidean distance treats the coordinates as numerical axes, so their scales affect the result.
For this definition to represent a useful similarity measure, the coordinates should be numeric and meaningfully comparable across observations. In practice, predictors may need to be transformed or scaled before this distance is calculated. Euclidean distance does not automatically correct for different units or ranges; it uses the coordinates as supplied.
Coordinates, Contributions, and Spherical Neighborhoods
For two coordinates, the formula is the familiar Pythagorean theorem. If the horizontal difference is \(a\) and the vertical difference is \(b\), the straight-line distance is \(\sqrt{a^2+b^2}\). With more coordinates, the squared difference along each axis is added in the same way. The term \((x_{ik}-x_{jk})^2\) is the contribution of feature \(k\) to the squared distance. Contributions are nonnegative, so differences in opposite directions do not cancel.
A neighborhood of radius \(r\) around a center \(c=(c_1,\ldots,c_p)\) consists of all points whose Euclidean distance from that center is no greater than \(r\). Expressing the distance condition without a square root gives:
In two dimensions, this region is a filled circle; in three dimensions, it is a filled ball. In higher dimensions it is called a ball as well. Its boundary is a sphere in the corresponding dimension. Points on the boundary are exactly distance \(r\) from the center. This geometric description explains why Euclidean distance defines spherical neighborhoods: the distance limit treats every direction from the center equally in the selected coordinate space.
The squared terms also have a direct interpretive use. If one feature's squared difference is most of the sum, that feature is chiefly responsible for the pair's separation in the current representation. This does not establish that the feature is more important for the underlying problem; it only describes its contribution to this particular distance calculation.
Worked Calculations
Worked Example: A Two-Feature Distance and Radius Check
A hypothetical insurer represents two regional portfolios by two already-scaled features: a claim-frequency coordinate and a claim-severity coordinate. Portfolio A has coordinates \((1,2)\), and Portfolio B has coordinates \((5,5)\). Calculate their Euclidean distance, find each feature's contribution to the squared distance, and determine whether B lies within radius 4 of A.
Method. Subtract the coordinates feature by feature, square each difference, add the squared differences, and take the square root. For the radius comparison, compare the resulting distance with 4.
The coordinate differences are \(1-5=-4\) and \(2-5=-3\). Their squared contributions are \((-4)^2=16\) and \((-3)^2=9\). Therefore the squared distance is \(16+9=25\), and the Euclidean distance is \(\sqrt{25}=5\).
The claim-frequency coordinate contributes \(16/25=0.64\), or 64%, of the squared distance. The claim-severity coordinate contributes \(9/25=0.36\), or 36%. Since \(5>4\), Portfolio B is outside the radius-4 neighborhood centered at A. As a check, the two perpendicular coordinate differences have lengths 4 and 3, so a straight-line separation of 5 agrees with the 3-4-5 right triangle.
Common mistake avoided. The sum of squared differences, 25, is not the Euclidean distance; the distance is its square root, 5. Comparing 25 directly with the radius 4 would use squared-distance units on one side and distance units on the other.
Worked Example: Several Moderate Differences Can Outweigh One Large Difference
A hypothetical portfolio analyst compares three observations using three numeric coordinates prepared for distance-based analysis. The reference observation is \(O=(0,0,0)\), while observations \(B=(3,0,0)\) and \(C=(0,2,2)\) have the listed coordinates. Calculate both distances from O, identify which observation is closer, and check membership in the radius-2.9 neighborhood around O.
Method. Calculate the squared coordinate differences for each pair, add them, and take the square root. Compare each distance with the given radius.
For B, the coordinate differences from O are \(3,0,0\). The squared differences are \(9,0,0\), so \(d_E(O,B)=\sqrt{9}=3\). For C, the differences are \(0,2,2\). The squared differences are \(0,4,4\), so \(d_E(O,C)=\sqrt{8}\), approximately \(2.828\).
Because \(\sqrt{8}<3\), C is closer to O, even though C differs on two coordinates while B differs on only one. This happens because the total squared contribution for C is 8, less than B's 9. Since \(2.828<2.9\), C lies within the radius-2.9 neighborhood. Since \(3>2.9\), B lies outside it.
Common mistake avoided. Counting the number of coordinates that differ does not determine which observation is closer. The calculation depends on the magnitudes of all coordinate differences after squaring.
Worked Example: Checking a Spherical Neighborhood in Three Dimensions
A hypothetical insurer represents a reference profile by center \(M=(1,1,1)\) in a three-feature space. Three other profiles are \(P=(3,2,1)\), \(Q=(2,3,3)\), and \(R=(0,0,2)\). Calculate each profile's distance from M, identify which are within radius 2, and state the largest squared-coordinate contribution for each profile.
Method. Subtract M from each profile, square each coordinate difference, sum the squares, and take the square root. A profile is within the neighborhood if its distance is at most 2, equivalently if its squared distance is at most \(2^2=4\).
For P, the differences from M are \((2,1,0)\). Their squares are \((4,1,0)\), summing to 5. Thus \(d_E(M,P)=\sqrt{5}\), approximately \(2.236\). P is outside the radius-2 neighborhood because \(5>4\). Its largest contribution is 4, from the first coordinate.
For Q, the differences are \((1,2,2)\). Their squares are \((1,4,4)\), summing to 9. Thus \(d_E(M,Q)=\sqrt{9}=3\). Q is outside because \(9>4\). The second and third coordinates tie for the largest contribution, each contributing 4.
For R, the differences are \((-1,-1,1)\). Their squares are \((1,1,1)\), summing to 3. Thus \(d_E(M,R)=\sqrt{3}\), approximately \(1.732\). R is inside because \(3<4\). All three coordinates contribute equally.
Check. The squared-distance comparisons give the same membership results as the distances: P and Q have squared distances greater than 4, while R has squared distance less than 4. The largest individual feature contribution does not by itself determine neighborhood membership; the total squared distance does.
Common mistake avoided. A profile can be outside the neighborhood even when no single coordinate difference exceeds the radius. P has coordinate differences of only 2, 1, and 0, but the sum of their squares is 5, which exceeds the squared radius 4.
What Distance Comparisons Tell You in Clustering
When observations are represented by feature vectors, their Euclidean distances provide one way to describe their proximity. If two observations are close, then their combined coordinate differences are small in this representation. If they are far apart, at least one squared difference, or the combined effect of several differences, is large. Clustering methods can use such distances to form or assess groups, but the distance alone does not establish that the groups are meaningful for a business or actuarial purpose.
Euclidean distance has useful geometric properties. Translating every observation by the same vector leaves pairwise distances unchanged because the coordinate differences do not change. Rotating the coordinate system without distorting it also preserves straight-line distances. However, changing the scale of one coordinate generally changes distances: multiplying that coordinate by a constant multiplies its differences by that constant and its squared contributions by the constant squared. This is why feature scaling choices can change which observations appear close.
Using squared Euclidean distance instead of Euclidean distance preserves the ordering of pairwise distances: if \(a\) and \(b\) are nonnegative, then \(a<b\) exactly when \(a^2<b^2\). It can therefore give the same nearest observation when used only to rank distances. But squared distance is not itself a distance metric in the usual sense; for example, it need not satisfy the triangle inequality. Also, a radius test must use consistent units: compare distance with \(r\), or squared distance with \(r^2\).
| Quantity | Calculation | Interpretation |
|---|---|---|
| Coordinate difference | \(x_{ik}-x_{jk}\) | Signed separation on one feature |
| Squared contribution | \((x_{ik}-x_{jk})^2\) | Nonnegative contribution of that feature to squared distance |
| Squared Euclidean distance | \(\sum_k(x_{ik}-x_{jk})^2\) | Total of the feature contributions |
| Euclidean distance | \(\sqrt{\sum_k(x_{ik}-x_{jk})^2}\) | Straight-line separation in the feature space |
Common Exam Traps
- Stopping at the sum of squares. The sum is squared Euclidean distance. Take its square root when the question asks for Euclidean distance.
- Using absolute differences instead. Adding \(|x_{ik}-x_{jk}|\) gives Manhattan distance, a different measure. Do not substitute it for the Euclidean formula.
- Comparing inconsistent quantities. For a radius \(r\), use \(d_E\le r\) or \(d_E^2\le r^2\), not \(d_E^2\le r\).
- Ignoring scale and representation. A feature measured on a much wider numerical range may dominate the squared contributions. Interpret distance in the coordinates actually used.
- Assuming one feature's contribution gives the whole answer. Neighborhood membership depends on the sum of all squared contributions, not the largest one alone.
Check Your Understanding
For each problem, calculate using the Euclidean formula and check that the units or radius comparison are consistent.
- Two observations have coordinates \((2,1)\) and \((-1,5)\). Calculate their Euclidean distance and the contribution of each coordinate to squared distance. (Answer: distance \(5\); squared contributions \(9\) and \(16\).)
- A point is \(x=(1,-1,2)\), and a neighborhood center is \(c=(3,2,2)\). Calculate the Euclidean distance from x to c, rounded to three decimals. (Answer: \(\sqrt{13}\approx3.606\).)
- A point differs from a center by \((2,2,1)\). Is it within the center's radius-3 neighborhood? Show the squared-distance check. (Answer: Yes; squared distance \(4+4+1=9=3^2\), so it is on the boundary.)
- Relative to \(A=(0,0)\), compare \(B=(4,0)\) and \(C=(2,2)\). Which is closer to A, and what is the distance difference? (Answer: C is closer; \(d_E(A,B)=4\), \(d_E(A,C)=\sqrt{8}\approx2.828\), difference approximately \(1.172\).)
- Two three-feature profiles differ by \((-1,2,-2)\). Calculate their Euclidean distance and the fraction of squared distance contributed by each coordinate. (Answer: distance \(3\); contributions are \(1/9\), \(4/9\), and \(4/9\).)