Get invited to our slack community and get access to opportunities and data science insights


euclid_distance(ftvec1, ftvec2) – Returns the square root of the sum of the squared differences: sqrt(sum((x – y)^2))

WITH docs as (
select 1 as docid, array(‘apple:1.0’, ‘orange:2.0’, ‘banana:1.0’, ‘kuwi:0’) as features
union all
select 2 as docid, array(‘apple:1.0’, ‘orange:0’, ‘banana:2.0’, ‘kuwi:1.0’) as features
union all
select 3 as docid, array(‘apple:2.0’, ‘orange:0’, ‘banana:2.0’, ‘kuwi:1.0’) as features
l.docid as doc1,
r.docid as doc2,
euclid_distance(l.features, r.features) as distance,
distance2similarity(euclid_distance(l.features, r.features)) as similarity
docs l
l.docid != r.docid
order by
doc1 asc,
distance asc;

doc1 doc2 distance similarity
1 2 2.4494898 0.28989795
1 3 2.6457512 0.2742919
2 3 1.0 0.5
2 1 2.4494898 0.28989795
3 2 1.0 0.5
3 1 2.6457512 0.2742919

Platforms: WhereOS, Spark, Hive
Class: hivemall.knn.distance.EuclidDistanceUDF

More functions can be added to WhereOS via Python or R bindings or as Java & Scala UDF (user-defined function), UDAF (user-defined aggregation function) and UDTF (user-defined table generating function) extensions. Custom libraries can be added on via Settings-page or installed from WhereOS Store.

Related Post

Leave a Comment