Learn R Programming

⚠️There's a newer version (1.0.6) of this package.Take me there.

R package recommenderlab - Lab for Developing and Testing Recommender Algorithms

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. Supported algorithms are:

  • User-based collborative filtering (UBCF)
  • Item-based collborative filtering (IBCF)
  • SVD with column-mean imputation (SVD)
  • Funk SVD (SVDF)
  • Alternating Least Squares (ALS)
  • Matrix factorization with LIBMF (LIBMF)
  • Association rule-based recommender (AR)
  • Popular items (POPULAR)
  • Randomly chosen items for comparison (RANDOM)
  • Re-recommend liked items (RERECOMMEND)
  • Hybrid recommendations (HybridRecommender)

For evaluation, the framework supports given-n and all-but-x protocols with

  • Train/test split
  • Cross-validation
  • Repeated bootstrap sampling

Evaluation measures are:

  • Rating errors: MSE, RMSE, MAE
  • Top-N recommendations: TPR/FPR (ROC), precision and recall

Installation

Stable CRAN version: install from within R with

install.packages("recommenderlab")

Current development version: Install from r-universe.

Usage

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.

library("recommenderlab")
data("MovieLense")

MovieLense100 <- MovieLense[rowCounts(MovieLense) > 100, ]
MovieLense100
## 358 x 1664 rating matrix of class 'realRatingMatrix' with 73610 ratings.

Train a user-based collaborative filtering recommender using a small training set.

train <- MovieLense100[1:100]
rec <- Recommender(train, method = "UBCF")
rec
## Recommender of type 'UBCF' for 'realRatingMatrix' 
## learned using 100 users.

Create top-N recommendations for new users (users 101 and 102).

pre <- predict(rec, MovieLense100[101:102], n = 5)
pre
## Recommendations as 'topNList' with n = 5 for 2 users.
as(pre, "list")
## $`0`
## [1] "M (1931)"                                 
## [2] "Braindead (1992)"                         
## [3] "Charade (1963)"                           
## [4] "Touch of Evil (1958)"                     
## [5] "Die xue shuang xiong (Killer, The) (1989)"
## 
## $`1`
## [1] "SubUrbia (1997)"        "Apostle, The (1997)"    "Dead Man (1995)"       
## [4] "War Room, The (1993)"   "Beautiful Thing (1996)"

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
## Evaluation scheme using all-but-5 items
## Method: 'cross-validation' with 10 run(s).
## Good ratings: >=4.000000
## Data set: 358 x 1664 rating matrix of class 'realRatingMatrix' with 73610 ratings.
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))
)

results <- evaluate(scheme, algorithms, type = "topNList",
  n=c(1, 3, 5, 10), progress = FALSE)

plot(results, annotate = 2, legend = "topleft")

Shiny App

A simple Shiny App running recommenderlab can be found at https://mhahsler-apps.shinyapps.io/Jester/ (source code).

References

Copy Link

Version

Install

install.packages('recommenderlab')

Monthly Downloads

2,565

Version

1.0.1

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Michael Hahsler

Last Published

June 17th, 2022

Functions in recommenderlab (1.0.1)

MSWeb

Anonymous web data from www.microsoft.com
dissimilarity

Dissimilarity and Similarity Calculation Between Rating Data
MovieLense

MovieLense Dataset (100k)
Recommender

Create a Recommender Model
Recommender-class

Class "Recommender": A Recommender Model
evaluationScheme

Creator Function for evaluationScheme
evaluationScheme-class

Class "evaluationScheme": Evaluation Scheme
getList

List and Data.frame Representation for Recommender Matrix Objects
evaluationResults-class

Class "evaluationResults": Results of the Evaluation of a Single Recommender Method
internalFunctions

Internal Utility Functions
HybridRecommender

Create a Hybrid Recommender
evaluate

Evaluate a Recommender Models
evaluationResultList-class

Class "evaluationResultList": Results of the Evaluation of a Multiple Recommender Methods
predict

Predict Recommendations
ratingMatrix

Class "ratingMatrix": Virtual Class for Rating Data
Jester5k

Jester dataset (5k sample)
funkSVD

Funk SVD for Matrices with Missing Data
calcPredictionAccuracy

Calculate the Prediction Error for a Recommendation
plot

Plot Evaluation Results
binaryRatingMatrix

Class "binaryRatingMatrix": A Binary Rating Matrix
normalize

Normalize the ratings
topNList

Class "topNList": Top-N List
realRatingMatrix

Class "realRatingMatrix": Real-valued Rating Matrix
sparseNAMatrix-class

Sparse Matrix Representation With NAs Not Explicitly Stored
Error

Error Calculation