我目前正在学习马氏距离,我觉得这很困难。为了更好地理解这个想法,我生成了 2 组随机值(x 和 y)和一个随机点,其中所有 3 的平均值 = 0 和标准偏差 = 1。如何计算它们之间的马氏距离?请在下面找到我的 Python 代码非常感谢您的帮助!
import numpy as np
from numpy import cov
from scipy.spatial import distance
generate 20 random values where mean = 0 and standard deviation = 1, assign one set to x and one to y
x = [random.normalvariate(0,1) for i in range(20)]
y = [random.normalvariate(0,1) for i in range(20)]
r_point = [random.normalvariate(0,1)] #that's my random point
sigma = cov(x, y)
print(sigma)
print("random point =", r_point)
#use the covariance to calculate the mahalanobis distance from a random point```