Book Image

Building a Recommendation System with R

Book Image

Building a Recommendation System with R

Overview of this book

Table of Contents (13 chapters)
Building a Recommendation System with R
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
References
Index

User-based collaborative filtering on binary data


Similar to IBCF, we need to use the Jaccard index for UBCF. Given two users, the index is computed as the number of items purchased by both the users divided by the number of items purchased by at least one of them. The mathematical symbols are the same as in the previous section:

Let's build the recommender model:

recc_model <- Recommender(data = recc_data_train, method = "UBCF", parameter = list(method = "Jaccard"))

Using the same commands as IBCF, let's recommend six movies to each user, and let's take a look at the first four users:

n_recommended <- 6
recc_predicted <- predict(object = recc_model, newdata = recc_data_test,n = n_recommended)
recc_matrix <- sapply(recc_predicted@items, function(x){colnames(ratings_movies)[x]
})
dim(recc_matrix)
## [1]   6 109
recc_matrix[, 1:4]

The Shawshank Redemption (1994)

Titanic (1997)

Casablanca (1942)

Cinema Paradiso (1988)

Braveheart (1995)

Lone Star (1996)

The Terminator (1984)

L...