Last active
August 29, 2015 14:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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