One of the most important tasks in building a recommendation engine is finding users that are similar. This guides in creating the recommendations that will be provided to these users. Let's see how to build this.
Create a new Python file, and import the following packages:
import json import numpy as np from pearson_score import pearson_score
Let's define a function to find similar users to the input user. It takes three input arguments: the database, input user, and the number of similar users that we are looking for. Our first step is to check whether the user is present in the database. If the user exists, we need to compute the Pearson correlation score between this user and all the other users in the database:
# Finds a specified number of users who are similar to the input user def find_similar_users(dataset, user, num_users): if user not in dataset: raise TypeError('User ' + user + ' not present in the dataset') # Compute...