Computing the Euclidean distance score
Now that we have sufficient background in machine learning pipelines and nearest neighbors classifier, let's start the discussion on recommendation engines. In order to build a recommendation engine, we need to define a similarity metric so that we can find users in the database who are similar to a given user. Euclidean distance score is one such metric that we can use to compute the distance between datapoints. We will focus the discussion towards movie recommendation engines. Let's see how to compute the Euclidean score between two users.
How to do it…
Create a new Python file, and import the following packages:
import json import numpy as np
We will now define a function to compute the Euclidean score between two users. The first step is to check whether the users are present in the database:
# Returns the Euclidean distance score between user1 and user2 def euclidean_score(dataset, user1, user2): if user1 not in dataset: raise TypeError...