O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required