Class UserKNN


  • public class UserKNN
    extends Recommender
    Implements user-to-user KNN based collaborative filtering
    • Field Detail

      • numberOfNeighbors

        protected int numberOfNeighbors
        Number of neighbors (k)
      • metric

        protected UserSimilarityMetric metric
        Similarity metric to compute the similarity between two users
      • aggregationApproach

        protected UserKNN.AggregationApproach aggregationApproach
        Aggregation approach used to aggregate k-nearest neighbors ratings
      • neighbors

        protected int[][] neighbors
        Contains the neighbors indexes of each user
    • Constructor Detail

      • UserKNN

        public UserKNN​(DataModel datamodel,
                       Map<String,​Object> params)
        Recommender constructor from a Map containing the recommender's hyper-parameters values. Map object must contains the following keys:
        • numberOfNeighbors: int value with the number of neighbors.
        • metric:: UserSimilarityMetric instance with the similarity metric to compute the similarity between two users.
        • aggregationApproach: UserKNN.AggregationApproach instance with the aggregation approach used to aggregate k-nearest neighbors ratings.
        Parameters:
        datamodel - DataModel instance
        params - Recommender's hyper-parameters values
      • UserKNN

        public UserKNN​(DataModel datamodel,
                       int numberOfNeighbors,
                       UserSimilarityMetric metric,
                       UserKNN.AggregationApproach aggregationApproach)
        Recommender constructor
        Parameters:
        datamodel - DataModel instance
        numberOfNeighbors - Number of neighbors (k)
        metric - Similarity metric to compute the similarity between two users
        aggregationApproach - Aggregation approach used to aggregate k-nearest neighbors ratings
    • Method Detail

      • fit

        public void fit()
        Description copied from class: Recommender
        Estimates model parameters given the hyper-parameters
        Specified by:
        fit in class Recommender
      • predict

        public double predict​(int userIndex,
                              int itemIndex)
        Description copied from class: Recommender
        Computes a rating prediction
        Specified by:
        predict in class Recommender
        Parameters:
        userIndex - Index of the user in the array of Users of the DataModel instance
        itemIndex - Index of the item in the array of Items of the DataModel instance
        Returns:
        Prediction