# Why does an imbalanced data set badly effect distance measures like Mahalanobis?

I'm relatively new to data science and I am struggling to understand why the Mahalanobis distance (or any other distance measure) applied to an imbalanced data-set becomes inaccurate. I have a data set that consists of three classes A, B and C. There are 100 observations for class A, 60 for class B, and 20 for class C. When I calculate the Mahalanobis distance between each class, the results do not appear consistent with my PCA (principal component analysis) plot. In the PCA plot, class C is the most separate class; however, the Mahalanobis distance does not reflect this.

For balanced data sets, i.e., where classes A, B and C have the same number of observations, this has never been an issue. The Mahalanobis distance has always quite accurately reflected the results of PCA for balanced data.

I have read some similar questions and answers on here about why imbalanced data must be handled carefully for classification algorithms, but is this the same for distance measures? From what I can tell the Mahalanobis distance doesn't explicitly depend on sample size.

Therefore, I ask why does this measure lose reliability for imbalanced data?

• could you please elaborate on: "When I calculate the Mahalanobis distance between each class"? Like previously stated Mahalanobis Distance is the distance between a point and a distribution . How are you using it to measure the distance between two classes? Commented Mar 17, 2021 at 20:20
• Hi, I believe it is possible to define the Mahalanobis distance as a dissimilarity/distance measure between two means, X and Y, of distributions. In my case, this is in 2D scores space. X would be the mean of PCA scores for one class, Y the other. Using the distance between two means gives a measure for the distance between two distributions. This literature, in particular the methods section, explains it very well: ncbi.nlm.nih.gov/pmc/articles/PMC3534867 Commented Mar 17, 2021 at 22:57