Now that we built all of the different parts of a recommendation engine, we are ready to generate movie recommendations. We will use all the functionality that we built in the previous recipes to build a movie recommendation engine. Let's see how to build it.
Create a new Python file, and import the following packages:
import json import numpy as np from euclidean_score import euclidean_score from pearson_score import pearson_score from find_similar_users import find_similar_users
We will define a function to generate movie recommendations for a given user. The first step is to check whether the user exists in the dataset:
# Generate recommendations for a given user def generate_recommendations(dataset, user): if user not in dataset: raise TypeError('User ' + user + ' not present in the dataset')
Let's compute the Pearson score of this user with all the other users in the dataset:
total_scores = {} similarity_sums = {} for...