All problems
Item-Based Cosine Predict
Problem
Predict a rating as the similarity-weighted average of the user's ratings on items similar to the target: sum(sim * rating) / sum(|sim|) over items present in both dicts.
Return 0.0 when there is no overlap or the weight sum is 0.
Hint
Item-item similarity weights the user's own ratings of related items.
Test cases
case 1
in: [{"a":5,"b":3},{"a":0.8,"b":0.4}]
expected: 4.333333333333333
case 2
in: [{"a":5,"b":1},{"a":0.5,"b":-0.5}]
expected: 2
case 3
in: [{"a":5},{"b":0.5}]
expected: 0
case 4
in: [{},{"a":0.5}]
expected: 0
Starter codePython
def item_based_cosine_predict(user_ratings, similarities):
# Your code here
pass4 test cases · run your code against them in the editor