欧氏距离H2O计算错误 [英] Wrong Euclidean distance H2O calculations R

查看:209
本文介绍了欧氏距离H2O计算错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有R的H2O来计算2个数据帧之间的欧式距离:

I am using H2O with R to calculate the euclidean distance between 2 data.frames:

set.seed(121)

#create the data
df1<-data.frame(matrix(rnorm(1000),ncol=10))
df2<-data.frame(matrix(rnorm(300),ncol=10))
#init h2o
h2o.init()

#transform to h2o
df1.h<-as.h2o(df1)
df2.h<-as.h2o(df2)

如果我使用常规计算,即第一行:

if I use normal calculations, i.e. the first row:

distance1<-sqrt(sum((df1[1,]-df2[1,])^2))

如果我使用H2O库:

distance.h2o<-h2o.distance(df1.h[1,],df2.h[1,],"l2")

print(distance1)
print(distance.h2o)

distance1和distance.h2o不相同.有人知道为什么吗?谢谢!

The distance1 and distance.h2o are not the same. Does anybody knows why? Thanks!!

推荐答案

似乎h2o.distance在不求平方根的情况下计算平方和:因此,求平方根即可得到标准结果.

It seems as if h2o.distance calculates the sum of squares, without taking the square root: so take the square root to get the standard result.

distance.h2o <- h2o.distance(df1.h[1,],df2.h[1,],"l2") 
sqrt(distance.h2o)

这篇关于欧氏距离H2O计算错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆