UUtah Fall 2026 | Data Mining | L4 - Metric Distances
Watch on YouTube →
Overview
Metric distances are modeling choices in data mining: they define which data points count as close, affect algorithm behavior, and can change project outcomes. The lecture develops the metric axioms and the Lp family (including Euclidean L2, Manhattan L1, and maximum-coordinate L∞), then introduces Mahalanobis distance for feature weighting and cosine-based measures for embeddings, distinguishing cosine distance from the angular metric.
Key takeaways
- A distance function is a modeling decision: changing it can change nearest neighbors, clusters, and downstream project results.
- The standard Lp metrics for p≥1 include Manhattan L1, Euclidean L2, and maximum-coordinate L∞; p<1 can violate the triangle inequality.
- Distances over mixed-unit features such as height and weight need scaling or weighting, because converting feet to inches can otherwise change comparisons without changing the underlying data.
- Mahalanobis distance, sqrt((a-b)^T M(a-b)), generalizes Euclidean distance: identity M recovers L2, diagonal M weights coordinates, and a full matrix can account for feature correlations.
- Cosine distance 1-cos(a,b) is not a metric: proportional vectors can have zero distance, and the triangle inequality still fails even when vectors are normalized.
- For normalized embedding vectors, angular distance arccos(a·b) measures spherical arc length and satisfies the metric properties.
Chapters
- In unsupervised data mining, a distance function is part of the model input because it determines which observations count as close.
- Common defaults can hide this choice; upcoming course work will compare distances and efficient ways to compute them.
- The homework is due Tuesday at 11:55 p.m.; experiments may take most of a day, so starting early is advised.
- The input space can be abstract, such as text or graphs, but the lecture focuses mainly on vectors in R^D.
- A dataset is written as x1 through xn, with each xi represented by D coordinates.
- A distance D(a,b) maps two inputs to a nonnegative real number: smaller values indicate greater closeness.
- For points a=(4,6) and b=(6,-1), Euclidean distance is sqrt((4-6)^2+(6-(-1))^2)=sqrt(53).
- In two dimensions, this is the straight-line length between the points, like measuring a taut string.
- The example anchors the familiar Euclidean distance before comparing alternative notions of distance.
- A metric is nonnegative and has identity of indiscernibles: D(a,b)=0 if and only if a=b.
- Symmetry requires D(a,b)=D(b,a), so reversing the input order does not change the distance.
- The triangle inequality requires D(a,b)≤D(a,c)+D(c,b), preventing a detour through c from being shorter than the direct route.
- A hash-based representation can assign distinct inputs to the same location, making their measured distance zero despite their difference.
- The lecture calls a distance that relaxes the 'only if' part of identity a quasi-metric; word embeddings can similarly merge distinct meanings, as with 'bank.'
- Asymmetric travel costs can arise from one-way roads or uphill versus downhill hiking; the driving time from A to B may differ from B to A.
- For vectors a,b in R^D, the Lp distance is (sum_i |ai-bi|^p)^(1/p), equivalently the p-norm of a-b.
- Each coordinate contributes according to its absolute difference raised to p; the final 1/p power returns the result to the original distance scale.
- The family includes several useful choices rather than prescribing Euclidean distance as the only option.
- At p=2, squaring coordinate differences, summing, and taking a square root gives the Euclidean distance by the Pythagorean theorem.
- At p=1, the distance is sum_i |ai-bi|, also called Manhattan distance.
- The Manhattan distance models travel along a grid: in Salt Lake City's street-grid analogy, the route length is the total horizontal and vertical movement.
- The L∞ distance is max_i |ai-bi|, the largest coordinate-wise difference.
- It corresponds to the limit of Lp distances as p grows, because the largest powered coordinate increasingly dominates the sum.
- The max definition avoids the tie issue that would arise from treating the limit as a sum of equally largest coordinates.
- If coordinates are measured in miles, a distance should also be measured in miles; the 1/p power restores the original units after exponentiation.
- An L2 ball of radius 1 is a circle, while an L1 ball is a diamond and an L∞ ball is a square.
- Changing the distance changes which points fall within a radius, so it can alter the relative closeness of two observations.
- For p values from 1 through infinity, the Lp unit balls expand from the L1 diamond toward the L∞ square.
- The lecture illustrates an L0.5 ball as nonconvex, unlike the L1, L2, and L∞ balls.
- For p<1, the triangle inequality can fail, so these expressions are not metrics; the standard L1, L2, and L∞ choices are common metric distances.
- Adding quantities with unrelated units is meaningless, as illustrated by a sign that sums a town's population, elevation in feet, and founding year into 4663.
- An unscaled Lp distance over height and weight can let measurement units determine the result rather than the intended importance of each feature.
- Changing height from feet to inches can change nearest-neighbor rankings even though the underlying people have not changed.
- Mahalanobis distance is defined as sqrt((a-b)^T M (a-b)), where M is a D-by-D matrix.
- A positive-definite M gives a metric; a positive-semidefinite M can assign zero distance to distinct points.
- Unlike a plain Lp distance, M provides a way to encode feature importance and address mismatched scales.
- Setting M to the identity matrix reduces Mahalanobis distance exactly to Euclidean L2 distance.
- A positive diagonal M weights individual coordinates; because the matrix appears inside a quadratic form, the effective coordinate scaling relates to the square roots of its diagonal entries.
- A full positive-definite matrix can represent a different basis and account for correlations so related coordinates are not naively counted twice.
- Cosine distance is 1-(a·b)/(||a|| ||b||), with values from 0 to 2 for nonzero vectors.
- Cosine similarity is the normalized dot product without subtracting it from 1; it is widely used with word and contextual embeddings such as BERT.
- Cosine-based measures emphasize vector direction, unlike Euclidean distance, which also responds to vector magnitude.
- Cosine distance is symmetric and nonnegative, but distinct vectors on the same ray normalize to the same point, violating strict identity; it also fails the triangle inequality.
- Restricting inputs to the unit sphere S^(D-1) restores the identity condition for cosine distance, but does not fix its triangle-inequality failure.
- Angular distance arccos(a·b) measures the great-circle arc between normalized vectors and is a metric on S^(D-1).
- Similarity scores and metric distances support different algorithms, so choosing between cosine similarity, cosine distance, and angular distance requires care.
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, UofU Data Science.