Created
January 21, 2016 02:17
-
-
Save sudipto80/84ea679cd85ca7f6f8c4 to your computer and use it in GitHub Desktop.
Cosine Similarity
This file contains hidden or 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 SimuDot (ratings :(float list)list) (a:int)(u:int)= | |
let num = List.zip ratings.[a] ratings.[u] | |
|> List.sumBy (fun item -> fst item * snd item) | |
let d1 = ratings.[a] |> List.sumBy (fun item -> item * item ) | |
let d2 = ratings.[u] |> List.sumBy (fun item -> item * item ) | |
if d1 = 0.0 || d2 = 0.0 then 0.0 else num / (sqrt d1 * sqrt d2) | |
let ratings = [[4.;0.;5.;5.];[4.;2.;1.;0.];[3.;0.;2.;4.];[4.;4.;0.;0.];[2.;1.;3.;5.]] | |
SimuDot ratings 0 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment