Skip to content

Instantly share code, notes, and snippets.

@marcelcaraciolo
Created August 21, 2012 19:11
Show Gist options
  • Save marcelcaraciolo/3418446 to your computer and use it in GitHub Desktop.
Save marcelcaraciolo/3418446 to your computer and use it in GitHub Desktop.
regularized correlation
def regularized_correlation(size, dot_product, rating_sum, \
rating2sum, rating_norm_squared, rating2_norm_squared,
virtual_cont, prior_correlation):
'''
The Regularized Correlation between two vectors A, B
RegularizedCorrelation = w * ActualCorrelation + (1 - w) * PriorCorrelation
where w = # actualPairs / (# actualPairs + # virtualPairs).
'''
unregularizedCorrelation = correlation(size, dot_product, rating_sum, \
rating2sum, rating_norm_squared, rating2_norm_squared)
w = size / float(size + virtual_cont)
return w * unregularizedCorrelation + (1.0 - w) * prior_correlation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment