英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论