User-based collaborative filtering and recommendations

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-to-User Similarity MatrixuserToUserSimMatrix <- cosine(  as.matrix(    # excluding CustomerID column    t(customerItemMatrix[, 2:dim(customerItemMatrix)[2]])  ))colnames(userToUserSimMatrix) <- customerItemMatrix$CustomerID

As is noticeable from this code, using the cosine function from the coop library, you can compute and build a cosine similarity matrix. One thing to note in this code is the fact that we transpose the customerItemMatrix before computing cosine similarities. This is to compute user-to-user similarities. Without ...

Get Hands-On Data Science for Marketing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.