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 ...