Hellinger Distance

The Hellinger distance is a measure of the similarity between two probability distributions. It is defined as:

H2(P,Q)=12∑i=1n(pi−qi)2H^2(P,Q) = \frac{1}{2} \sum_{i=1}^{n} (\sqrt{p_i} - \sqrt{q_i})^2

where PP and QQ are two probability distributions over the same set of nn events.

In the continuous case, the Hellinger distance between two probability density functions p(x)p(x) and q(x)q(x) is defined as: H2(p,q)=12∫(p(x)−q(x))2dx=1−∫p(x)q(x)dxH^2(p,q) = \frac{1}{2} \int (\sqrt{p(x)} - \sqrt{q(x)})^2 dx = 1 - \int \sqrt{p(x)q(x)} dx

Mahalanobis Distance

import numpy as np 
import pandas as pd  
import scipy as stats 
  
# calculateMahalanobis function to calculate 
# the Mahalanobis distance 
def calculateMahalanobis(y=None, data=None, cov=None): 
  
    y_mu = y - np.mean(data) 
    if not cov: 
        cov = np.cov(data.values.T) 
    inv_covmat = np.linalg.inv(cov) 
    left = np.dot(y_mu, inv_covmat) 
    mahal = np.dot(left, y_mu.T) 
    return mahal.diagonal() 
Search notes
Graph View