pkg <- 'recommenderlab' source("https://raw.githubusercontent.com/mhahsler/pkg_helpers/main/pkg_helpers.R") pkg_title(pkg)
Provides a research infrastructure to develop and evaluate collaborative filtering recommender algorithms. This includes a sparse representation for user-item matrices, many popular algorithms, top-N recommendations, and cross-validation. The package supports rating (e.g., 1-5 stars) and unary (0-1) data sets.
pkg_usage(pkg) pkg_citation(pkg, 2)
The framework supports given-n and all-but-x protocols with
Available evaluation measures are
pkg_install(pkg)
Load the package and prepare a dataset (included in the package). The MovieLense data contains user ratings for movies on a 1 to 5 star scale. We only use here users with more than 100 ratings.
set.seed(1234) library("recommenderlab") data("MovieLense") MovieLense100 <- MovieLense[rowCounts(MovieLense) > 100, ] MovieLense100
Train a user-based collaborative filtering recommender using a small training set.
train <- MovieLense100[1:300] rec <- Recommender(train, method = "UBCF") rec
Create top-N recommendations for new users (users 301 and 302).
pre <- predict(rec, MovieLense100[301:302], n = 5) pre
as(pre, "list")
Use a 10-fold cross-validation scheme to compare the top-N lists of several algorithms. Movies with 4 or more stars are considered a good recommendation. We plot true negative vs. true positive rate for top-N lists of different lengths.
scheme <- evaluationScheme(MovieLense100, method = "cross-validation", k = 10, given = -5, goodRating = 4) scheme algorithms <- list( "random items" = list(name = "RANDOM", param = NULL), "popular items" = list(name = "POPULAR", param = NULL), "user-based CF" = list(name = "UBCF", param = list(nn = 3)), "item-based CF" = list(name = "IBCF", param = list(k = 100)) ) results <- evaluate(scheme, algorithms, type = "topNList", n=c(1, 3, 5, 10), progress = FALSE) plot(results, annotate = 2, legend = "topleft")
A simple Shiny App running recommenderlab can be found at https://mhahsler-apps.shinyapps.io/Jester/ (source code).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.