How to do it...

  1. First, load the library and dataset:
> library(recommenderlab) 
> library(ggplot2) 
> data(MovieLense) 
  1. Next, preprocess the dataset to create a new dataset containing relevant users and movies:
> ratings_movies <- MovieLense[rowCounts(MovieLense) > 50, colCounts(MovieLense)>100] 
> ratings_movies 

There are 560 users and 332 ratings with 560 x 332 dimensional rating matrix of class realRatingMatrix with 55298 ratings.

  1. Prepare the data for validation using the k-fold approach:
> n_fold <- 4 
> items_to_keep <- 15 
> rating_threshold <- 3 
> eval_sets <- evaluationScheme(data = ratings_movies, method = "cross-validation",k = n_fold, given = items_to_keep, goodRating = rating_threshold) 
  1. Count the number of items that we have ...

Get R Data Analysis Cookbook - Second Edition 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.