Collaborative filtering predicts a rating from the ratings that similar users gave the same item, or that the same user gave similar items. Y is an (n_users, n_items) array and mask a boolean array of the same shape marking observed entries.
similarity(Y, mask, kind): the (n_users, n_users) user-user similarity, computed for each pair over their co-rated items only. kind="cosine": . kind="pearson": the Pearson correlation of the two users' co-rated ratings (means taken over the co-rated items). A pair with fewer than 2 co-rated items, or a zero denominator, gets similarity 0; the diagonal is 1. (For item-item similarity call it on the transposes.)
predict_cf(Y, mask, u, i, k, mode, kind): with mode="user", take the users who rated item , keep the with the highest similarity to (ties: smaller index), and return
where is a user's mean over all their observed ratings. With mode="item" do the same on the transposed problem (items rated by , item means, item-item similarity). If the denominator is 0, return the mean (user mode) or (item mode). Return a Python float.