org.mymedialite.ratingprediction
Class KNN

java.lang.Object
  extended by org.mymedialite.ratingprediction.RatingPredictor
      extended by org.mymedialite.ratingprediction.IncrementalRatingPredictor
          extended by org.mymedialite.ratingprediction.KNN
All Implemented Interfaces:
java.lang.Cloneable, IRecommender, IIncrementalRatingPredictor, IRatingPredictor
Direct Known Subclasses:
ItemKNN, UserKNN

public abstract class KNN
extends IncrementalRatingPredictor

Base class for rating predictors that use some kind of kNN. The method is described in section 2.2 of the paper below. One difference is that we support several iterations of alternating optimization, instead of just one. Literature: Yehuda Koren: Factor in the Neighbors: Scalable and Accurate Collaborative Filtering, Transactions on Knowledge Discovery from Data (TKDD), 2009. http://public.research.att.com/~volinsky/netflix/factorizedNeighborhood.pdf This recommender supports incremental updates. See also org.mymedialite.itemrec.KNN


Field Summary
protected  UserItemBaseline baseline_predictor
           
protected  CorrelationMatrix correlation
          Correlation matrix over some kind of entity.
 int k
          Number of neighbors to take into account for predictions.
 
Fields inherited from class org.mymedialite.ratingprediction.IncrementalRatingPredictor
updateItems, updateUsers
 
Fields inherited from class org.mymedialite.ratingprediction.RatingPredictor
maxItemID, maxRating, maxUserID, minRating, ratings
 
Constructor Summary
KNN()
          Default constructor
 
Method Summary
 double getRegI()
          Get the regularization constant for the user bias of the underlying baseline predictor
 double getRegU()
          Get the regularization constant for the user bias of the underlying baseline predictor.
 void loadModel(java.lang.String filename)
          Get the model parameters from a file
 void saveModel(java.lang.String filename)
          Save the model parameters to a file
 void setRatings(IRatings ratings)
           
 void setRegI(double regI)
          Set the regularization constant for the item bias of the underlying baseline predictor.
 void setRegU(double regU)
          Set the regularization constant for the user bias of the underlying baseline predictor.
 
Methods inherited from class org.mymedialite.ratingprediction.IncrementalRatingPredictor
addItem, addRating, addUser, getUpdateItems, getUpdateUsers, removeItem, removeRating, removeUser, setUpdateItems, setUpdateUsers, updateRating
 
Methods inherited from class org.mymedialite.ratingprediction.RatingPredictor
canPredict, clone, getMaxRating, getMinRating, getRatings, predict, setMaxRating, setMinRating, toString, train
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mymedialite.ratingprediction.IRatingPredictor
getMaxRating, getMinRating, setMaxRating, setMinRating
 
Methods inherited from interface org.mymedialite.IRecommender
canPredict, predict, toString, train
 

Field Detail

baseline_predictor

protected UserItemBaseline baseline_predictor

k

public int k
Number of neighbors to take into account for predictions.


correlation

protected CorrelationMatrix correlation
Correlation matrix over some kind of entity.

Constructor Detail

KNN

public KNN()
Default constructor

Method Detail

setRatings

public void setRatings(IRatings ratings)
Overrides:
setRatings in class RatingPredictor

getRegU

public double getRegU()
Get the regularization constant for the user bias of the underlying baseline predictor.

Returns:
the regularization parameter

setRegU

public void setRegU(double regU)
Set the regularization constant for the user bias of the underlying baseline predictor.

Parameters:
regU - the regularization parameter

getRegI

public double getRegI()
Get the regularization constant for the user bias of the underlying baseline predictor

Returns:
the regularization parameter

setRegI

public void setRegI(double regI)
Set the regularization constant for the item bias of the underlying baseline predictor.

Parameters:
regI - the regularization parameter

saveModel

public void saveModel(java.lang.String filename)
               throws java.io.IOException
Description copied from interface: IRecommender
Save the model parameters to a file

Specified by:
saveModel in interface IRecommender
Specified by:
saveModel in class RatingPredictor
Parameters:
filename - the file to write to
Throws:
java.io.IOException

loadModel

public void loadModel(java.lang.String filename)
               throws java.io.IOException
Description copied from interface: IRecommender
Get the model parameters from a file

Specified by:
loadModel in interface IRecommender
Specified by:
loadModel in class RatingPredictor
Parameters:
filename - the file to read from
Throws:
java.io.IOException