Skip to content

Instantly share code, notes, and snippets.

@misaxi
Last active August 29, 2015 14:20
Show Gist options
  • Save misaxi/6c206cfad90f9e6716c9 to your computer and use it in GitHub Desktop.
Save misaxi/6c206cfad90f9e6716c9 to your computer and use it in GitHub Desktop.
Jaccard Similarity F# http://en.wikipedia.org/wiki/Jaccard_index Good for fuzzy searching
let jaccard (a:string) (b:string) =
let set1 = Set.ofSeq a
let set2 = Set.ofSeq b
if Set.isEmpty set1 && Set.isEmpty set2
then
1.0
else
let i = Set.intersect set1 set2
let u = set1 + set2
(float)(Set.count i) / (float)(Set.count u)
jaccard "hello world" "helo wrd"
|> printfn "%A"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment