On The Surprising Behavior of Distance Metrics
On The Surprising Behavior of Distance Metrics
1 Introduction
In recent years, high dimensional search and retrieval have become very well
studied problems because of the increased importance of data mining applica-
tions [1], [2], [3], [4], [5], [8], [10], [11]. Typically, most real applications which
require the use of such techniques comprise very high dimensional data. For such
applications, the curse of high dimensionality tends to be a major obstacle in the
development of data mining techniques in several ways. For example, the per-
formance of similarity indexing structures in high dimensions degrades rapidly,
so that each query requires the access of almost all the data [1].
J. Van den Bussche and V. Vianu (Eds.): ICDT 2001, LNCS 1973, pp. 420–434, 2001.
c Springer-Verlag Berlin Heidelberg 2001
On the Surprising Behavior of Distance Metrics 421
It has been argued in [6], that under certain reasonable assumptions on the
data distribution, the ratio of the distances of the nearest and farthest neighbors
to a given target in high dimensional space is almost 1 for a wide variety of data
distributions and distance functions. In such a case, the nearest neighbor problem
becomes ill defined, since the contrast between the distances to different data
points does not exist. In such cases, even the concept of proximity may not
be meaningful from a qualitative perspective: a problem which is even more
fundamental than the performance degradation of high dimensional algorithms.
In most high dimensional applications the choice of the distance metric is
not obvious; and the notion for the calculation of similarity is very heuristical.
Given the non-contrasting nature of the distribution of distances to a given
query point, different measures may provide very different orders of proximity
of points to a given query point. There is very little literature on providing
guidance for choosing the correct distance measure which results in the most
meaningful notion of proximity between two records. Many high dimensional
indexing structures and algorithms use the euclidean distance metric as a natural
extension of its traditional use in two- or three-dimensional spatial applications.
In this paper, we discuss the general
Pd behavior of the commonly used Lk norm
(x, y ∈ Rd , k ∈ Z, Lk (x, y) = i=1 (kxi − y i kk )1/k ) in high dimensional space.
The Lk norm distance function is also susceptible to the dimensionality curse
for many classes of data distributions [6]. Our recent results [9] seem to suggest
that the Lk -norm may be more relevant for k = 1 or 2 than values of k ≥ 3. In
this paper, we provide some surprising theoretical and experimental results in
analyzing the dependency of the Lk norm on the value of k. More specifically,
we show that the relative contrasts of the distances to a query point depend
heavily on the Lk metric used. This provides considerable evidence that the
meaningfulness of the Lk norm worsens faster with increasing dimensionality for
higher values of k. Thus, for a given problem with a fixed (high) value of the
dimensionality d, it may be preferable to use lower values of k. This means that
the L1 distance metric (Manhattan Distance metric) is the most preferable for
high dimensional applications, followed by the Euclidean Metric (L2 ), then the
L3 metric, and so on. Encouraged by this trend, we examine the behavior of
fractional distance metrics, in which k is allowed to be a fraction smaller than 1.
We show that this metric is even more effective at preserving the meaningfulness
of proximity measures. We back up our theoretical results with empirical tests on
real and synthetic data showing that the results provided by fractional distance
metrics are indeed practically useful. Thus, the results of this paper have strong
implications for the choice of distance metrics for high dimensional data mining
problems. We specifically show the improvements which can be obtained by
applying fractional distance metrics to the standard k-means algorithm.
This paper is organized as follows. In the next section, we provide a theo-
retical analysis of the behavior of the Lk norm in very high dimensionality. In
section 3, we discuss fractional distance metrics and provide a theoretical analy-
sis of their behavior. In section 4, we provide the empirical results, and section
5 provides summary and conclusions.
422 C.C. Aggarwal, A. Hinneburg, and D.A. Keim
In order to present our convergence results, we first establish some notations and
definitions in Table 1.
Table 1. Notations and Basic Definitions
Notation Definition
d Dimensionality of the data space
N Number of data points
F 1-dimensional data distribution in (0, 1)
Xd Data point from F d with each coordinate drawn from F
distkd (x, y) Distance between (x1 , . . . xd ) and (y 1 , . . . y d )
Pd
using Lk metric = i=1 [(xi1 − xi2 )k ]1/k
k · kk Distance of a vector to the origin (0, . . . , 0)
using the function distkd (·, ·)
k
Dmaxd = max{kXd kk } Farthest distance of the N points
to the origin using the distance metric Lk
Dminkd = min{kXd kk } Nearest distance of the N points
to the origin using the distance metric Lk
E[X], var[X] Expected value and variance of a random variable X
Yd →p c A vector sequence Y1 , . . . , Yd converges in probability to a
constant vector c if: ∀ > 0 limd→∞ P [distd (Yd , c) ≤ ] = 1
Theorem 1. Beyer
et. al. (Adapted for Lk metric)
kXd kk Dmaxk k
d −Dmind
If limd→∞ var E[kXd kk ] = 0 , then Dmink
→p 0.
d
Proof. See [6] for proof of a more general version of this result.
The result of the theorem [6] shows that the difference between the maxi-
mum and minimum distances to a given query point 1 does not increase as fast
as the nearest distance to any point in high dimensional space. This makes a
proximity query meaningless and unstable because there is poor discrimination
between the nearest and furthest neighbor. Henceforth, we will refer to the ratio
Dmaxk k
d −Dmind
Dmink
as the relative contrast.
d
Dmaxk −Dmink
The results in [6] use the value of d
Dmink
d
as an interesting criterion
d
for meaningfulness. In order to provide more insight, in the following we analyze
the behavior for different distance metrics in high-dimensional space. We first
assume a uniform distribution of data points and show our results for N = 2
points. Then, we generalize the results to an arbitrary number of points and
arbitrary distributions.
1
In this paper, we consistently use the origin as the query point. This choice does not
affect the generality of our results, though it simplifies our algebra considerably.
On the Surprising Behavior of Distance Metrics 423
Proof. This is because if L is the expected difference between the maximum and
minimum of two randomly drawn points, then the same value for n points drawn
from the same distribution must be in the range (L, (n − 1) · L).
The results can be modified for arbitrary distributions of N points in a data-
base by introducing the constant factor Ck . In that case, the general dependency
1 1
of Dmax − Dmin on d k − 2 remains unchanged. A detailed proof is provided in
the Appendix; a short outline of the reasoning behind the result is available in
[9].
Lemma 2.
h [9] Let F be ian arbitrary distribution of N = 2 points. Then,
Dmaxk k
d −Dmind
limd→∞ E d1/k−1/2
= Ck , where Ck is some constant dependent on k.
Thus, this result shows that in high dimensional space Dmaxkd − Dminkd in-
creases at the rate of d1/k−1/2 , independent of the data distribution. This means
that for the manhattan distance metric, the value of this expression diverges to
∞; for the Euclidean distance metric, the expression is bounded by constants
whereas for all other distance metrics, it converges to 0 (see Figure 1). Further-
more, the convergence is faster when the value of k of the Lk metric increases.
This provides the insight that higher norm parameters provide poorer contrast
between the furthest and nearest neighbor. Even more insight may be obtai-
ned by examining the exact behavior of the relative contrast as opposed to the
absolute distance between the furthest and nearest point.
On the Surprising Behavior of Distance Metrics 425
1.15 1.9 25
p=2 p=2 p=1
1.1 1.8
1.05 1.7 20
1 1.6
15
0.95 1.5
0.9 1.4
10
0.85 1.3
0.8 1.2 5
0.75 1.1
0.7 1 0
20 40 60 80 100 120 140 160 180 200 20 40 60 80 100 120 140 160 180 200 20 40 60 80 100 120 140 160 180 200
200 8e+06
150 6e+06
100 4e+06
50 2e+06
0 0
20 40 60 80 100 120 140 160 180 200 20 40 60 80 100 120 140 160 180 200
1/k
P Ad P Bd 1
min{ 1/k , 1/k } → (7)
d d k+1
N=10,000
N=1,000
4
N=100
1
0.8 f=1
3.5 f=0.75
0.6 f=0.5
3 f=0.25
0.4
RELATIVE CONTRAST
2.5 0.2
2
0
-0.2
1.5
-0.4
1 -0.6
-0.8
0.5
-1
0 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
0 1 2 3 4 5 6 7 8 9 10
PARAMETER OF DISTANCE NORM
The result of the previous section that the Manhattan metric (k = 1) provides
the best discrimination in high-dimensional data spaces is the motivation for
looking into distance metrics with k < 1. We call these metrics fractional distance
metrics. A fractional distance metric distfd (Lf norm) for f ∈ (0, 1) is defined
as:
d
X i 1/f
distfd (x, y) = (x − y i )f .
i=1
h i r
|P Ad −P Bd | 1 1
We intend to show that E dl−1/2 = C · (f +1) 1/f 2·f +1 . The
Pd P d
difference of distances is |P Ad − P Bd | = { i=1 (Pi )f }1/f − { i=1 (Qi )f }1/f
Pd P d
= { i=1 (Pi )f }l − { i=1 (Qi )f }l . Note that the above expression is of the form
Pl−1
|al − bl | = |a − b| · ( r=0 ar · bl−r−1 ). Therefore, |P Ad − P Bd | can be written as
Pd Pl−1
{ i=1 |(Pi )f − (Qi )f |} · { r=0 (QAd )r · (QBd )l−r−1 }. By dividing both sides by
d1/f −1/2 and regrouping the right hand side we get:
Pd Xl−1 r l−r−1
|P Ad − P Bd | i=1 |(Pi )f − (Qi )f | QAd QBd
→p { √ }·{ · } (10)
d1/f −1/2 d r=0
d d
f f
This
√ random variable (Pi ) − (Qi ) has zero mean fand standard deviation which
is 2 · σ where σ is the standard deviation of (Pi ) . The sum of different values
of (Pi )f − (Qi )f over d dimensions will √ converge to normal distribution with
mean 0 and standard deviation 2 · σ · d because of the central limit theorem.
Consequently,
√ the expected mean average deviation of this normal distribution
is C · σ · d for some constant C. Therefore, we have:
s
|(P Ad )f − (P Bd )f | f 1
limd→∞ E √ =C ·σ =C · . (12)
d f +1 2·f +1
The above result shows that the absolute difference between the maximum
and minimum for the fractional distance metric increases at the rate of d1/f −1/2 .
Thus, the smaller the fraction, the greater the rate of absolute divergence bet-
ween the maximum and minimum value. Now, we will examine the relative
contrast of the fractional distance metric.
This result is true for the case of arbitrary values f (not just f = 1/l) and
N , but the use of these specific values of f helps considerably in simplification of
the proof of the result. The empirical simulation in Figure 2, shows the behavior
for arbitrary values of f and N . The curve for each value of N is different but all
curves fit the general trend of reduced contrast with increased value of f . Note
that the value of the relative contrast for both, the case of integral distance
metric Lk and fractional distance metric Lf is the same in the boundary case
when f = k = 1.
The above results show that fractional distance metrics provide better con-
trast than integral distance metrics both in terms of the absolute distributions
of points to a given query point and relative distances. This is a surprising result
in light of the fact that the Euclidean distance metric is traditionally used in
a large variety of indexing structures and data mining applications. The wide-
spread use of the Euclidean distance metric stems from the natural extension
of applicability to spatial database systems (many multidimensional indexing
structures were initially proposed in the context of spatial systems). However,
from the perspective of high dimensional data mining applications, this natural
interpretability in 2 or 3-dimensional spatial systems is completely irrelevant.
Whether the theoretical behavior of the relative contrast also translates into
practically useful implications for high dimensional data mining applications is
an issue which we will examine in greater detail in the next section.
4 Empirical Results
In this section, we show that our surprising findings can be directly applied to
improve existing mining techniques for high-dimensional data. For the experi-
ments, we use synthetic and real data. The synthetic data consists of a number
of clusters (data inside the clusters follow a normal distribution and the cluster
centers are uniformly distributed). The advantage of the synthetic data sets is
that the clusters are clearly separated and any clustering algorithm should be
able to identify them correctly. For our experiments we used one of the most wi-
dely used standard clustering algorithms - the k-means algorithm. The data set
used in the experiments consists of 6 clusters with 10000 data points each and
no noise. The dimensionality was chosen to be 20. The results of our experiments
show that the fractional distance metrics provides a much higher classification
rate which is about 99% for the fractional distance metric with f = 0.3 versus
89% for the Euclidean metric (see figure 4). The detailed results including the
confusion matrices obtained are provided in the appendix.
For the experiments with real data sets, we use some of the classification
problems from the UCI machine learning repository 5 . All of these problems
are classification problems which have a large number of feature variables, and
a special variable which is designated as the class label. We used the following
simple experiment: For each of the cases that we tested on, we stripped off the
5
http : //www.cs.uci.edu/˜mlearn
430 C.C. Aggarwal, A. Hinneburg, and D.A. Keim
100
95
90
Classification Rate
85
80
75
70
65
60
55
50
0 0.5 1 1.5 2 2.5 3
Distance Parameter
class variable from the data set and considered the feature variables only. The
query points were picked from the original database, and the closest l neighbors
were found to each target point using different distance metrics. The technique
was tested using the following two measures:
1. Class Variable Accuracy: This was the primary measure that we used
in order to test the quality of the different distance metrics. Since the class va-
riable is known to depend in some way on the feature variables, the proximity
of objects belonging to the same class in feature space is evidence of the mea-
ningfulness of a given distance metric. The specific measure that we used was
the total number of the l nearest neighbors that belonged to the same class as
the target object over all the different target objects. Needless to say, we do not
intend to propose this rudimentary unsupervised technique as an alternative to
classification models, but use the classification performance only as an evidence
of the meaningfulness (or lack of meaningfulness) of a given distance metric. The
class labels may not necessarily always correspond to locality in feature space;
therefore the meaningfulness results presented are evidential in nature. However,
a consistent effect on the class variable accuracy with increasing norm parameter
does tend to be a powerful way of demonstrating qualitative trends.
2. Noise Stability: How does the quality of the distance metric vary with
more or less noisy data? We used noise masking in order to evaluate this aspect.
In noise masking, each entry in the database was replaced by a random entry
with masking probability pc . The random entry was chosen from a uniform
distribution centered at the mean of that attribute. Thus, when pc is 1, the data
is completely noisy. We studied how each of the two problems were affected by
noise masking.
In Table 3, we have illustrated some examples of the variation in performance
for different distance metrics. Except for a few exceptions, the major trend in
this table is that the accuracy performance decreases with increasing value of the
norm parameter. We have show the table in the range L0.1 to L10 because it was
easiest to calculate the distance values without exceeding the numerical ranges in
the computer representation. We have also illustrated the accuracy performance
when the L∞ metric is used. One interesting observation is that the accuracy
with the L∞ distance metric is often worse than the accuracy value by picking
a record from the database at random and reporting the corresponding target
On the Surprising Behavior of Distance Metrics 431
Table 3. Number of correct class label matches between nearest neighbor and target
4 3.5
L(0.1)
3.5 L(1)
3
L(10)
ACCURACY RATIO TO RANDOM MATCHING
3
2.5
2.5
ACCURACY RATIO 2
1.5
1.5
1
1 ACCURACY OF RANDOM MATCHING
ACCURACY OF RANDOM MATCHING
0.5
0.5
0 0
0 1 2 3 4 5 6 7 8 9 10 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
PARAMETER OF DISTANCE NORM USED NOISE MASKING PROBABILITY
Fig. 5. Accuracy depending on the norm Fig. 6. Accuracy depending on noise mas-
parameter king
value. This trend is observed because of the fact that the L∞ metric only looks
at the dimension at which the target and neighbor are furthest apart. In high
dimensional space, this is likely to be a very poor representation of the nearest
neighbor. A similar argument is true for Lk distance metrics (for high values of
k) which provide undue importance to the distant (sparse/noisy) dimensions.
It is precisely this aspect which is reflected in our theoretical analysis of the
relative contrast, which results in distance metrics with high norm parameters
to be poorly discriminating between the furthest and nearest neighbor.
In Figure 5, we have shown the variation in the accuracy of the class variable
matching with k, when the Lk norm is used. The accuracy on the Y -axis is
reported as the ratio of the accuracy to that of a completely random matching
scheme. The graph is averaged over all the data sets of Table 3. It is easy to see
that there is a clear trend of the accuracy worsening with increasing values of
the parameter k.
We also studied the robustness of the scheme to the use of noise masking.
For this purpose, we have illustrated the performance of three distance metrics
in Figure 6: L0.1 , L1 , and L10 for various values of the masking probability on
the machine data set. On the X-axis, we have denoted the value of the masking
probability, whereas on the Y -axis we have the accuracy ratio to that of a com-
pletely random matching scheme. Note that when the masking probability is 1,
then any scheme would degrade to a random method. However, it is interesting
to see from Figure 6 that the L10 distance metric degrades much faster to the
432 C.C. Aggarwal, A. Hinneburg, and D.A. Keim
References
1. Weber R., Schek H.-J., Blott S.: A Quantitative Analysis and Performance Study
for Similarity-Search Methods in High-Dimensional Spaces. VLDB Conference Pro-
ceedings, 1998.
2. Bennett K. P., Fayyad U., Geiger D.: Density-Based Indexing for Approximate
Nearest Neighbor Queries. ACM SIGKDD Conference Proceedings, 1999.
3. Berchtold S., Böhm C., Kriegel H.-P.: The Pyramid Technique: Towards Breaking
the Curse of Dimensionality. ACM SIGMOD Conference Proceedings, June 1998.
4. Berchtold S., Böhm C., Keim D., Kriegel H.-P.: A Cost Model for Nearest Neighbor
Search in High Dimensional Space. ACM PODS Conference Proceedings, 1997.
5. Berchtold S., Ertl B., Keim D., Kriegel H.-P. Seidl T.: Fast Nearest Neighbor
Search in High Dimensional Spaces. ICDE Conference Proceedings, 1998.
6. Beyer K., Goldstein J., Ramakrishnan R., Shaft U.: When is Nearest Neighbors
Meaningful? ICDT Conference Proceedings, 1999.
7. Shaft U., Goldstein J., Beyer K.: Nearest Neighbor Query Performance for Unsta-
ble Distributions. Technical Report TR 1388, Department of Computer Science,
University of Wisconsin at Madison.
8. Guttman, A.: R-Trees: A Dynamic Index Structure for Spatial Searching. ACM
SIGMOD Conference Proceedings, 1984.
9. Hinneburg A., Aggarwal C., Keim D.: What is the nearest neighbor in high dimen-
sional spaces? VLDB Conference Proceedings, 2000.
10. Katayama N., Satoh S.: The SR-Tree: An Index Structure for High Dimensional
Nearest Neighbor Queries. ACM SIGMOD Conference Proceedings, 1997.
11. Lin K.-I., Jagadish H. V., Faloutsos C.: The TV-tree: An Index Structure for High
Dimensional Data. VLDB Journal, Volume 3, Number 4, pages 517–542, 1992.
On the Surprising Behavior of Distance Metrics 433
Appendix
Here we provide a detailed proof of Lemma 2, which proves our modified conver-
gence results for arbitrary distributions of points. This Lemma shows that the
asymptotical rate of convergence of the absolute difference of distances between
the nearest and furthest points is dependent on the distance norm used. To re-
cap, we restate Lemma 2.
Lemma 2: h Let Fk be ankarbitrary
i distribution of N = 2 points. Then,
Dmaxd −Dmind
limd→∞ E d1/k−1/2
= Ck , where Ck is some constant dependent on k.
|(P Ad )k − (P Bd )k |
|P Ad − P Bd | = Pk−1 (15)
k−r−1 (P B )r
r=0 (P Ad ) d
X
k−1 k−r−1 r
(k−1)/k
P Ad /d1/k · P Bd /d1/k →p k · (µF ,k ) (17)
r=0
Confusion Matrices. We have illustrated the confusion matrices for two dif-
ferent values of p below. As illustrated, the confusion matrix for using the value
p = 0.3 is significantly better than the one obtained using p = 2.
Table 4. Confusion Matrix- p=2, (rows for prototype, colums for cluster)
1208 82 9711 4 10 14
0 2 0 0 6328 4
1 9872 104 32 11 0
8750 8 74 9954 1 18
39 0 10 8 8 9948
2 36 101 2 3642 16
Table 5. Confusion Matrix- p=0.3, (rows for prototype, colums for cluster)
51 115 9773 10 37 15
0 17 24 0 9935 14
15 10 9 9962 0 4
1 9858 66 5 19 1
8 0 9 3 9 9956
9925 0 119 20 0 10