Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-218

User-Based CF Predict

Problem

Predict a rating with user-based collaborative filtering: sum over neighbors with known ratings of sim * rating divided by the sum of |sim|; null ratings are skipped.

Return 0.0 when there are no usable neighbors or the weight sum is 0.

Hint

Only neighbors who rated the item contribute to the weighted average.

Test cases

case 1
in: [[4,null,2],[0.8,0.5,0.9]]
expected: 2.941176470588235
case 2
in: [[5,1],[0.5,-0.5]]
expected: 2
case 3
in: [[null,null],[0.5,0.5]]
expected: 0
case 4
in: [[4,null],[0,0]]
expected: 0
Starter codePython
def user_based_cf_predict(ratings, similarities):
    # Your code here
    pass

4 test cases · run your code against them in the editor