April 2018
Beginner
552 pages
13h 58m
English
import json import numpy as np
# Returns the Pearson correlation score between user1 and user2
def pearson _dist_score(dataset, FirstUser, SecondUser):
if FirstUser not in dataset:
raise TypeError('User ' + FirstUser + ' not present in the dataset')
if SecondUser not in dataset:
raise TypeError('User ' + SecondUser + ' not present in the dataset')
# Movies rated by both FirstUser and SecondUser Both_User_rated = {} for item in dataset[FirstUser]: ...