org.mymedialite.ratingprediction
Class TimeAwareBaseline

java.lang.Object
  extended by org.mymedialite.ratingprediction.RatingPredictor
      extended by org.mymedialite.ratingprediction.TimeAwareRatingPredictor
          extended by org.mymedialite.ratingprediction.TimeAwareBaseline
All Implemented Interfaces:
java.lang.Cloneable, IIterativeModel, IRecommender, IRatingPredictor, ITimeAwareRatingPredictor
Direct Known Subclasses:
TimeAwareBaselineWithFrequencies

public class TimeAwareBaseline
extends TimeAwareRatingPredictor
implements IIterativeModel

Time-aware bias model. Model described in equation (10) of BellKor Grand Prize documentation for the Netflix Prize (see below). The optimization problem is described in equation (12). The default hyper-parameter values are set to the ones shown in the report. For datasets other than Netflix, you may want to find better parameters. Literature: Yehuda Koren: The BellKor Solution to the Netflix Grand Prize This recommender does currently NOT support incremental updates.


Field Summary
 double alphaLearnRate
          Learn rate for the user-wise alphas.
 double beta
          Beta parameter for modeling the drift in the user bias.
 int binSize
          Bin size in days for modeling the time-dependent item bias.
 double itemBiasByTimeBinLearnRate
          Learn rate for the bin-wise item bias.
 double itemBiasLearnRate
          Learn rate for the item bias.
 int numIter
          Number of iterations over the dataset to perform.
 double regAlpha
          Regularization for the user-wise alphas.
 double regI
          Regularization for the item bias.
 double regItemBiasByTimeBin
          Regularization for the bin-wise item bias.
 double regU
          Regularization for the user bias.
 double regUserBiasByDay
          Regularization for the day-wise user bias.
 double regUserScaling
          Regularization for the user scaling factor.
 double regUserScalingByDay
          Regularization for the day-wise user scaling factor.
 double userBiasByDayLearnRate
          Learn rate for the day-wise user bias.
 double userBiasLearnRate
          Learn rate for the user bias.
 double userScalingByDayLearnRate
          Learn rate for the day-wise user scaling factor.
 double userScalingLearnRate
          Learn rate for the user-wise scaling factor.
 
Fields inherited from class org.mymedialite.ratingprediction.TimeAwareRatingPredictor
timed_ratings
 
Fields inherited from class org.mymedialite.ratingprediction.RatingPredictor
maxItemID, maxRating, maxUserID, minRating, ratings
 
Constructor Summary
TimeAwareBaseline()
          Default constructor.
 
Method Summary
 double computeLoss()
          Compute the current loss of the model
 int getNumIter()
          Get the number of iterations to run the training
protected  void initModel()
          Initialize the model parameters.
 void iterate()
          Run one iteration (= pass over the training data)
 void loadModel(java.lang.String filename)
          Get the model parameters from a file
 double predict(int user_id, int item_id)
          Predict the rating or score for a given user-item combination.
 double predict(int user_id, int item_id, java.util.Date time)
          predict rating at a certain point in time.
protected  double predict(int user_id, int item_id, int day, int bin)
          Predict the specified user_id, item_id, day and bin.
protected  int relativeDay(java.util.Date date)
          Given a Date object, return the day relative to the first rating day in the dataset.
 void saveModel(java.lang.String filename)
          Save the model parameters to a file
 void setNumIter(int numIter)
          Set the number of iterations to run the training
 java.lang.String toString()
          Return a string representation of the recommender
 void train()
          Learn the model parameters of the recommender from the training data
protected  void updateParameters(int u, int i, int day, int bin, double err)
          Single SGD step: update the parameter values for one user and one item.
 
Methods inherited from class org.mymedialite.ratingprediction.TimeAwareRatingPredictor
getRatings, getTimedRatings, setRatings, setTimedRatings
 
Methods inherited from class org.mymedialite.ratingprediction.RatingPredictor
canPredict, clone, getMaxRating, getMinRating, setMaxRating, setMinRating
 
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
 

Field Detail

numIter

public int numIter
Number of iterations over the dataset to perform.


binSize

public int binSize
Bin size in days for modeling the time-dependent item bias.


beta

public double beta
Beta parameter for modeling the drift in the user bias.


userBiasLearnRate

public double userBiasLearnRate
Learn rate for the user bias.


itemBiasLearnRate

public double itemBiasLearnRate
Learn rate for the item bias.


alphaLearnRate

public double alphaLearnRate
Learn rate for the user-wise alphas.


itemBiasByTimeBinLearnRate

public double itemBiasByTimeBinLearnRate
Learn rate for the bin-wise item bias.


userBiasByDayLearnRate

public double userBiasByDayLearnRate
Learn rate for the day-wise user bias.


userScalingLearnRate

public double userScalingLearnRate
Learn rate for the user-wise scaling factor.


userScalingByDayLearnRate

public double userScalingByDayLearnRate
Learn rate for the day-wise user scaling factor.


regU

public double regU
Regularization for the user bias.


regI

public double regI
Regularization for the item bias.


regAlpha

public double regAlpha
Regularization for the user-wise alphas.


regItemBiasByTimeBin

public double regItemBiasByTimeBin
Regularization for the bin-wise item bias.


regUserBiasByDay

public double regUserBiasByDay
Regularization for the day-wise user bias.


regUserScaling

public double regUserScaling
Regularization for the user scaling factor.


regUserScalingByDay

public double regUserScalingByDay
Regularization for the day-wise user scaling factor.

Constructor Detail

TimeAwareBaseline

public TimeAwareBaseline()
Default constructor.

Method Detail

setNumIter

public void setNumIter(int numIter)
Description copied from interface: IIterativeModel
Set the number of iterations to run the training

Specified by:
setNumIter in interface IIterativeModel

getNumIter

public int getNumIter()
Description copied from interface: IIterativeModel
Get the number of iterations to run the training

Specified by:
getNumIter in interface IIterativeModel

train

public void train()
Description copied from interface: IRecommender
Learn the model parameters of the recommender from the training data

Specified by:
train in interface IRecommender
Specified by:
train in class RatingPredictor

relativeDay

protected int relativeDay(java.util.Date date)
Given a Date object, return the day relative to the first rating day in the dataset.

Parameters:
date - the date/time of the rating event
Returns:
the day relative to the first rating day in the dataset

initModel

protected void initModel()
Initialize the model parameters.


iterate

public void iterate()
Description copied from interface: IIterativeModel
Run one iteration (= pass over the training data)

Specified by:
iterate in interface IIterativeModel

updateParameters

protected void updateParameters(int u,
                                int i,
                                int day,
                                int bin,
                                double err)
Single SGD step: update the parameter values for one user and one item. the user ID the item ID the day of the rating the day bin of the rating the current error made for this rating


predict

public double predict(int user_id,
                      int item_id)
Description copied from interface: IRecommender
Predict the rating or score for a given user-item combination.

Specified by:
predict in interface IRecommender
Specified by:
predict in class RatingPredictor
Parameters:
user_id - the user ID
item_id - the item ID
Returns:
the predicted score/rating for the given user-item combination

predict

protected double predict(int user_id,
                         int item_id,
                         int day,
                         int bin)
Predict the specified user_id, item_id, day and bin. Assumes user and item IDs are valid. the user ID the item ID the day of the rating the day bin of the rating


predict

public double predict(int user_id,
                      int item_id,
                      java.util.Date time)
Description copied from interface: ITimeAwareRatingPredictor
predict rating at a certain point in time.

Specified by:
predict in interface ITimeAwareRatingPredictor
Specified by:
predict in class TimeAwareRatingPredictor
Parameters:
user_id - the user ID
item_id - the item ID
time - the time of the rating event
Returns:
the prediction value

computeLoss

public double computeLoss()
Description copied from interface: IIterativeModel
Compute the current loss of the model

Specified by:
computeLoss in interface IIterativeModel
Returns:
the current loss; -1 if not implemented

toString

public java.lang.String toString()
Description copied from interface: IRecommender
Return a string representation of the recommender

Specified by:
toString in interface IRecommender
Overrides:
toString in class RatingPredictor
Returns:
the class name and all hyperparameters, separated by space characters.

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