To learn more detail about Jaccard similarity and Jaccard distance please visit Jaccard similarity and Jaccard distance theory
Code:
function union(x,y){
var z = x.concat(y);// adding two array
j = [...new Set(z)];//unique elements
return j;
}
function intersects(a,b){
return [...new Set(a)].filter(x => new Set(b).has(x));
}
function Jaccard_similarity(x,y){
var u = union(x,y);// call union function
var i = intersects(x,y); // call intesects fuction
var x = u.length;
var y = i.length
return y/x;
}
function Jaccard_distance(x,y){
return (1-Jaccard_similarity(x,y))
}
console.log("Jaccard_similarity is "+Jaccard_similarity([0,1,2,5,6],[0,2,3,4,5,7,9]))
console.log("Jaccard_distance is " +Jaccard_distance([0,1,2,5,6],[0,2,3,4,5,7,9]))
No comments:
Post a Comment