C# Class MyMediaLite.RatingPrediction.MatrixFactorization

Simple matrix factorization class, learning is performed by stochastic gradient descent (SGD)

Factorizing the observed rating values using a factor matrix for users and one for items.

NaN values in the model occur if values become too large or too small to be represented by the type float. If you encounter such problems, there are three ways to fix them: (1) (preferred) Use BiasedMatrixFactorization, which is more stable. (2) Change the range of rating values (1 to 5 works generally well with the default settings). (3) Decrease the learn_rate.

This recommender supports incremental updates.

Inheritance: MyMediaLite.RatingPrediction.IncrementalRatingPredictor, IIterativeModel, IFoldInRatingPredictor
ファイルを表示 Open project: zenogantner/MML-KDD Class Usage Examples

Protected Properties

Property Type Description
global_bias double
item_factors Matrix
user_factors Matrix

Public Methods

Method Description
AddRating ( int user_id, int item_id, double rating ) : void
ComputeFit ( ) : double
ComputeLoss ( ) : double

Compute the regularized loss

Iterate ( ) : void
LoadModel ( string filename ) : void
MatrixFactorization ( ) : System

Default constructor

Predict ( int user_id, int item_id ) : double

Predict the rating of a given user for a given item

If the user or the item are not known to the recommender, the global average is returned. To avoid this behavior for unknown entities, use CanPredict() to check before.

RemoveItem ( int item_id ) : void
RemoveRating ( int user_id, int item_id ) : void
RemoveUser ( int user_id ) : void
RetrainItem ( int item_id ) : void

Updates the latent factors of an item

RetrainUser ( int user_id ) : void

Updates the latent factors on a user

SaveModel ( string filename ) : void
ToString ( ) : string
Train ( ) : void
UpdateRating ( int user_id, int item_id, double rating ) : void

Protected Methods

Method Description
AddItem ( int item_id ) : void
AddUser ( int user_id ) : void
InitModel ( ) : void

Initialize the model data structure

Iterate ( IList rating_indices, bool update_user, bool update_item ) : void

Iterate once over rating data and adjust corresponding factors (stochastic gradient descent)

Predict ( int user_id, int item_id, bool bound ) : double

Private Methods

Method Description
LearnFactors ( IList rating_indices, bool update_user, bool update_item ) : void

Method Details

AddItem() protected method

protected AddItem ( int item_id ) : void
item_id int
return void

AddRating() public method

public AddRating ( int user_id, int item_id, double rating ) : void
user_id int
item_id int
rating double
return void

AddUser() protected method

protected AddUser ( int user_id ) : void
user_id int
return void

ComputeFit() public method

public ComputeFit ( ) : double
return double

ComputeLoss() public method

Compute the regularized loss
public ComputeLoss ( ) : double
return double

InitModel() protected method

Initialize the model data structure
protected InitModel ( ) : void
return void

Iterate() public method

public Iterate ( ) : void
return void

Iterate() protected method

Iterate once over rating data and adjust corresponding factors (stochastic gradient descent)
protected Iterate ( IList rating_indices, bool update_user, bool update_item ) : void
rating_indices IList a list of indices pointing to the ratings to iterate over
update_user bool true if user factors to be updated
update_item bool true if item factors to be updated
return void

LoadModel() public method

public LoadModel ( string filename ) : void
filename string
return void

MatrixFactorization() public method

Default constructor
public MatrixFactorization ( ) : System
return System

Predict() public method

Predict the rating of a given user for a given item
If the user or the item are not known to the recommender, the global average is returned. To avoid this behavior for unknown entities, use CanPredict() to check before.
public Predict ( int user_id, int item_id ) : double
user_id int the user ID
item_id int the item ID
return double

Predict() protected method

protected Predict ( int user_id, int item_id, bool bound ) : double
user_id int
item_id int
bound bool
return double

RemoveItem() public method

public RemoveItem ( int item_id ) : void
item_id int
return void

RemoveRating() public method

public RemoveRating ( int user_id, int item_id ) : void
user_id int
item_id int
return void

RemoveUser() public method

public RemoveUser ( int user_id ) : void
user_id int
return void

RetrainItem() public method

Updates the latent factors of an item
public RetrainItem ( int item_id ) : void
item_id int the item ID
return void

RetrainUser() public method

Updates the latent factors on a user
public RetrainUser ( int user_id ) : void
user_id int the user ID
return void

SaveModel() public method

public SaveModel ( string filename ) : void
filename string
return void

ToString() public method

public ToString ( ) : string
return string

Train() public method

public Train ( ) : void
return void

UpdateRating() public method

public UpdateRating ( int user_id, int item_id, double rating ) : void
user_id int
item_id int
rating double
return void

Property Details

global_bias protected_oe property

The bias (global average)
protected double global_bias
return double

item_factors protected_oe property

Matrix containing the latent item factors
protected Matrix item_factors
return Matrix

user_factors protected_oe property

Matrix containing the latent user factors
protected Matrix user_factors
return Matrix