Recently, I revisited the concept of the median, and I will record the key points while they are fresh.
When performing outlier removal or clipping, we often need a "baseline"; for example, for a collection of non-negative data, we might consider values greater than 50 times the baseline to be outliers. How, then, should this baseline be chosen? A commonly used metric is the mean; however, the mean is easily "skewed" by outliers. As a result, using it as a baseline may be biased toward outliers and thus miss some outliers. In such cases, we can consider choosing the median as the baseline.
Basic Properties #
For one-dimensional data points
Because all the data points directly participate in calculating the mean, as soon as a few points are exceptionally large, the mean also grows larger accordingly, thereby interfering with outlier detection.
The idea of the median is to find a "neutral party" among the data to serve as the baseline. Specifically, it seeks to find a dividing point such that the amount of data greater than or equal to this dividing point is the same as the amount less than or equal to it; therefore, it is also called the "50% quantile (Quantile-50%)". If
From the definition of the median, we can already see its robustness against disturbances: as long as the relative order of each number with respect to the median does not change, the median will not change. Furthermore, we can introduce the "breakdown point" to describe this capability, which is "the minimum proportion of outliers that can cause the result to tend to infinity". For the mean, the answer is approximately 0, because it only takes a single point tending to infinity for the mean to tend to infinity; for the median, however, it is 50%, because more than half of the numbers must tend to infinity for the median to tend to infinity.
The drawback of the median is that it is more complicated to compute than the mean, since it requires at least some degree of sorting on the data, which is especially unfriendly to distributed computing scenarios. Fortunately, most scenarios do not require an extremely precise median, so there is some room for maneuver—for example, computing local medians first and then computing a global mean or median, which can significantly reduce communication.
An Optimization Perspective #
Interestingly, from an optimization perspective, we can unify the mean and the median:
The notation
That is, when
High-Dimensional Spaces #
From an optimization perspective, we can also understand why the median is more resistant to the influence of outliers than the mean: suppose there is an exceptionally large
In addition, another advantage of the optimization perspective is that it readily generalizes to high-dimensional spaces. As we know, the concept of the mean generalizes very easily to high dimensions: for a set of vectors
However, from an optimization perspective, this generalization is very natural:
where
Unfortunately, the median vector has no analytical solution, and we usually compute it based on the following Weiszfeld iteration:
Further Generalization #
Obviously, we can also consider a more general extension:
Denoting
Setting
Substituting
In addition, there is another less commonly used form of the median vector in high-dimensional space, which replaces the Euclidean norm with the L1 norm:
This is called the "Coordinate-wise Median". Because it essentially takes the one-dimensional median component-wise, it is relatively simple to compute; however, since it lacks clear geometric meaning, its use cases are relatively fewer.
Summary #
This article briefly summarizes the concept and properties of the median, as well as its generalization in high-dimensional spaces.