Class ItemKNN
- java.lang.Object
-
- es.upm.etsisi.cf4j.recommender.Recommender
-
- es.upm.etsisi.cf4j.recommender.knn.ItemKNN
-
public class ItemKNN extends Recommender
Implements item-to-item KNN based collaborative filtering
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classItemKNN.AggregationApproachAvailable aggregation approaches to merge k-nearest neighbors ratings
-
Field Summary
Fields Modifier and Type Field Description protected ItemKNN.AggregationApproachaggregationApproachAggregation approach used to aggregate k-nearest neighbors ratingsprotected ItemSimilarityMetricmetricSimilarity metric to compute the similarity between two itemsprotected int[][]neighborsContains the neighbors indexes of each itemprotected intnumberOfNeighborsNumber of neighbors (k)-
Fields inherited from class es.upm.etsisi.cf4j.recommender.Recommender
datamodel
-
-
Constructor Summary
Constructors Constructor Description ItemKNN(DataModel datamodel, int numberOfNeighbors, ItemSimilarityMetric metric, ItemKNN.AggregationApproach aggregationApproach)Recommender constructorItemKNN(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 voidfit()Estimates model parameters given the hyper-parametersdoublepredict(int userIndex, int itemIndex)Computes a rating predictionStringtoString()-
Methods inherited from class es.upm.etsisi.cf4j.recommender.Recommender
getDataModel, predict
-
-
-
-
Field Detail
-
numberOfNeighbors
protected int numberOfNeighbors
Number of neighbors (k)
-
metric
protected ItemSimilarityMetric metric
Similarity metric to compute the similarity between two items
-
aggregationApproach
protected ItemKNN.AggregationApproach aggregationApproach
Aggregation approach used to aggregate k-nearest neighbors ratings
-
neighbors
protected int[][] neighbors
Contains the neighbors indexes of each item
-
-
Constructor Detail
-
ItemKNN
public ItemKNN(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:: ItemSimilarityMetric instance with the similarity metric to compute the similarity between two items.
- aggregationApproach: ItemKNN.AggregationApproach instance with the aggregation approach used to aggregate k-nearest neighbors ratings.
- Parameters:
datamodel- DataModel instanceparams- Recommender's hyper-parameters values
-
ItemKNN
public ItemKNN(DataModel datamodel, int numberOfNeighbors, ItemSimilarityMetric metric, ItemKNN.AggregationApproach aggregationApproach)
Recommender constructor- Parameters:
datamodel- DataModel instancenumberOfNeighbors- Number of neighbors (k)metric- Similarity metric to compute the similarity between two itemsaggregationApproach- Aggregation approach used to aggregate k-nearest neighbors ratings
-
-
Method Detail
-
fit
public void fit()
Description copied from class:RecommenderEstimates model parameters given the hyper-parameters- Specified by:
fitin classRecommender
-
predict
public double predict(int userIndex, int itemIndex)Description copied from class:RecommenderComputes a rating prediction- Specified by:
predictin 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
-
-