How to do it...

  1. We will create a new Python file and import the following packages into it:
import json 
import numpy as np  
  1. 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') 
  1. 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 ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.