

def calcSim(item_pair, rating_pairs):
    ' \n    For each item-item pair, return the specified similarity measure,\n    along with co_raters_count\n    '
    (sum_xx, sum_xy, sum_yy, sum_x, sum_y, n) = (0.0, 0.0, 0.0, 0.0, 0.0, 0)
    for rating_pair in rating_pairs:
        sum_xx += (np.float(rating_pair[0]) * np.float(rating_pair[0]))
        sum_yy += (np.float(rating_pair[1]) * np.float(rating_pair[1]))
        sum_xy += (np.float(rating_pair[0]) * np.float(rating_pair[1]))
        n += 1
    cos_sim = cosine(sum_xy, np.sqrt(sum_xx), np.sqrt(sum_yy))
    return (item_pair, (cos_sim, n))

dataset/ETHPy150Open evancasey/spark-knn-recommender/algorithms/itemSimilarity.py calcSim/original