规范化欧氏距离 – python

huangapple go评论52阅读模式
英文:

normalize Euclidean distance - python

问题

def euclidean_distance(n):
    L = np.linalg.cholesky( [[1.0, 0.60], [0.60, 1.0]])
    
    uncorrelated = np.random.standard_normal((2, n))
    correlated = np.dot(L, uncorrelated)
        
    A = correlated[0]
    B = correlated[1]
    
    v = np.linalg.norm(A-B)
        
    return v

v50 = euclidean_distance(50)
v1000 = euclidean_distance(1000)

欧氏距离在计算时使用更多数据点时会变得更大我该如何对距离进行归一化以便能够比较`v50``v1000`之间的相似性
英文:
def euclidean_distance(n):
	L = np.linalg.cholesky( [[1.0, 0.60], [0.60, 1.0]])
	
	uncorrelated = np.random.standard_normal((2, n))
	correlated = np.dot(L, uncorrelated)
		
	A = correlated[0]
	B = correlated[1]
	
	v = np.linalg.norm(A-B)
		
	return v

v50 = euclidean_distance(50)
v1000 = euclidean_distance(1000)

The euclidean distance is larger the more data points I use in the computation. How can I normalize the distances so that I can compare similarity between v50 and v1000?

答案1

得分: 1

你可以通过将它们除以在每次计算中使用的数据点数的平方根来归一化距离。尝试这样做:

    v = np.linalg.norm(A-B) / np.sqrt(n)
英文:

you can normalize the distances by dividing them by the square root of the number of data points used in each computation. try this:

v = np.linalg.norm(A-B) / np.sqrt(n)

huangapple
  • 本文由 发表于 2023年2月16日 02:15:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75463912.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定