@staticmethod
def sim_pearson(p1, p2):
    # Get the list of mutually rated items
    si = [item for item in p1 if item in p2]

    # Find the number of elements
    n = len(si)

    # if they have no ratings in common, return 0
    if n != 0:
        # Add up all the preferences
        sum1 = sum([p1[it] for it in si])
        sum2 = sum([p2[it] for it in si])

        # Sum up the squares
        sum1Sq = sum([pow(p1[it], 2) for it in si])
        sum2Sq = sum([pow(p2[it], 2) for it in si])

        # Sum up the products
        pSum = sum([p1[it] * p2[it] for it in si])

        # Calculate Pearson score
        num = pSum - (sum1 * sum2 / n)
        den = sqrt((sum1Sq - pow(sum1, 2) / n) * (sum2Sq - pow(sum2, 2) / n))
        if den == 0:
            return 0
        r = num / den
        return r
    return 0
Returns the Pearson correlation coefficient for p1 and p2
dataset/ETHPy150Open fcurella/django-recommends/recommends/similarities.py/sim_pearson