Created
August 21, 2012 19:10
cosine
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
def cosine(dot_product, rating_norm_squared, rating2_norm_squared): | |
''' | |
The cosine between two vectors A, B | |
dotProduct(A, B) / (norm(A) * norm(B)) | |
''' | |
numerator = dot_product | |
denominator = rating_norm_squared * rating2_norm_squared | |
return (numerator / (float(denominator))) if denominator else 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment