Class UserKNN
- java.lang.Object
-
- es.upm.etsisi.cf4j.recommender.Recommender
-
- es.upm.etsisi.cf4j.recommender.knn.UserKNN
-
public class UserKNN extends Recommender
Implements user-to-user KNN based collaborative filtering
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UserKNN.AggregationApproach
Available aggregation approaches to merge k-nearest neighbors ratings
-
Field Summary
Fields Modifier and Type Field Description protected UserKNN.AggregationApproach
aggregationApproach
Aggregation approach used to aggregate k-nearest neighbors ratingsprotected UserSimilarityMetric
metric
Similarity metric to compute the similarity between two usersprotected int[][]
neighbors
Contains the neighbors indexes of each userprotected int
numberOfNeighbors
Number of neighbors (k)-
Fields inherited from class es.upm.etsisi.cf4j.recommender.Recommender
datamodel
-
-
Constructor Summary
Constructors Constructor Description UserKNN(DataModel datamodel, int numberOfNeighbors, UserSimilarityMetric metric, UserKNN.AggregationApproach aggregationApproach)
Recommender constructorUserKNN(DataModel datamodel, Map<String,Object> params)
Recommender constructor from a Map containing the recommender's hyper-parameters values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fit()
Estimates model parameters given the hyper-parametersdouble
predict(int userIndex, int itemIndex)
Computes a rating predictionString
toString()
-
Methods inherited from class es.upm.etsisi.cf4j.recommender.Recommender
getDataModel, predict
-
-
-
-
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 instanceparams
- Recommender's hyper-parameters values
-
UserKNN
public UserKNN(DataModel datamodel, int numberOfNeighbors, UserSimilarityMetric metric, UserKNN.AggregationApproach aggregationApproach)
Recommender constructor- Parameters:
datamodel
- DataModel instancenumberOfNeighbors
- Number of neighbors (k)metric
- Similarity metric to compute the similarity between two usersaggregationApproach
- 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 classRecommender
-
predict
public double predict(int userIndex, int itemIndex)
Description copied from class:Recommender
Computes a rating prediction- Specified by:
predict
in classRecommender
- Parameters:
userIndex
- Index of the user in the array of Users of the DataModel instanceitemIndex
- Index of the item in the array of Items of the DataModel instance- Returns:
- Prediction
-
-