User-based filtering

The most basic user-based collaborative filtering can be implemented by initializing the previously described components, as follows:

First, load the data model:

StringItemIdFileDataModel model = new StringItemIdFileDataModel( 
    new File("/datasets/chap6/BX-Book-Ratings.csv", ";"); 

Next, define how to calculate how the users are correlated; for example, using the Pearson correlation:

UserSimilarity similarity =  
  new PearsonCorrelationSimilarity(model); 

Next, define how to tell which users are similar, that is, the users that are close to each other, according to their ratings:

UserNeighborhood neighborhood =  
  new ThresholdUserNeighborhood(0.1, similarity, model); 

Now, we can initialize a GenericUserBasedRecommender default ...

Get Machine Learning in Java - 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.