The first step in building a recommendation engine includes finding similar users in the database. The Euclidean distance score is one of the measures to find similarities.
NumPy (Numerical Python) needs to be installed on Raspberry Pi 3 to calculate Euclidean distance. Readers can install numpy
by typing the following command in the Raspberry Pi 3 Terminal:
sudo apt-get -y install python-numpy
- 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...