- We will create a new Python file and import the following packages into it:
import json import numpy as np
- To calculate the Euclidean score between two users, we will define a new function. Let's check the presence of the users in the database:
# The following code will return the Euclidean distance score between user1 and user2: def euclidean_dist_score(dataset, FirstUser, SecondUser): if FirstUser not in dataset: raiseTypeError('User ' + FirstUser + ' not present in the dataset') if SecondUser not in dataset: raiseTypeError('User ' + SecondUser + ' not present in the dataset')
- We will now extract the movies that have been rated by both users. Then we will compute the score:
# Movies rated by both FirstUser and SecondUser ...