I'm trying to pick Scala up. This is a simple heuristic that checks a similarity value between two sets. I've done this a million times in Java or Python. The function works, but I'm certain I am not doing this the Scala way.val a : List[Int] = List(1,1,2,2,3)val b : List[Int] = List(1,2,3,4,5)def calculateBags(a: List[Int], b: List[Int]): Double = {    val a_counts = a.groupBy(x=>x).map(y=> y._1->y._2.size)    val b_counts = b.groupBy(x=>x).map(y=> y._1->y._2.size)    var count = 0    a_counts.foreach{ x=>        var k = x._1        var t = x._2        if (b_counts.contains(k)) {            count+= Math.min(t,b_counts(k))        }    }    (count.toDouble)/(a.size+b.size)}
Refactor jaccard similarity the Scala way
scala;machine learning