In order to build a user-based collaborative filtering algorithm, we need to compute cosine similarities between users. Let's take a look at the following code:
user_user_sim_matrix = pd.DataFrame( cosine_similarity(customer_item_matrix))
As is noticeable from this code, we are using the cosine_similarity function from the sklearn package's metrics.pairwise module. This function computes pairwise cosine similarities between the samples and outputs the results as an array type. Then, we create a pandas DataFrame with this output array and store it into a variable named user_user_sim_matrix, which stands for user-to-user similarity matrix. The result looks as follows:
As you can see from ...