This class implements collaborative filtering (cf).
CF (arma::mat &data, const size_t numUsersForSimilarity=5, const size_t rank=0)
Initialize the CF object. const arma::sp_mat & CleanedData () const
Get the cleaned data matrix. const arma::mat & Data () const
Get the data matrix. void Factorizer (const FactorizerType &f)
Sets factorizer for NMF. void GetRecommendations (const size_t numRecs, arma::Mat< size_t > &recommendations)
Generates the given number of recommendations for all users. void GetRecommendations (const size_t numRecs, arma::Mat< size_t > &recommendations, arma::Col< size_t > &users)
Generates the given number of recommendations for the specified users. const arma::mat & H () const
Get the Item Matrix. void NumUsersForSimilarity (const size_t num)
Sets number of users for calculating similarity. size_t NumUsersForSimilarity () const
Gets number of users for calculating similarity. void Rank (const size_t rankValue)
Sets rank parameter for matrix factorization. size_t Rank () const
Gets rank parameter for matrix factorization. const arma::mat & Rating () const
Get the Rating Matrix. std::string ToString () const
Returns a string representation of this object. const arma::mat & W () const
Get the User Matrix.
void CleanData ()
Converts the User, Item, Value Matrix to User-Item Table. void InsertNeighbor (const size_t queryIndex, const size_t pos, const size_t neighbor, const double value, arma::Mat< size_t > &recommendations, arma::mat &values) const
Helper function to insert a point into the recommendation matrices.
arma::sp_mat cleanedData
Cleaned data matrix. arma::mat data
Initial data matrix. FactorizerType factorizer
Instantiated factorizer object. arma::mat h
Item matrix. size_t numUsersForSimilarity
Number of users for similarity. size_t rank
Rank used for matrix factorization. arma::mat rating
Rating matrix. arma::mat w
User matrix.
This class implements Collaborative Filtering (CF).
This implementation presently supports Alternating Least Squares (ALS) for collaborative filtering.
A simple example of how to run Collaborative Filtering is shown below.
extern arma::mat data; // (user, item, rating) table extern arma::Col<size_t> users; // users seeking recommendations arma::Mat<size_t> recommendations; // Recommendations CF<> cf(data); // Default options. // Generate 10 recommendations for all users. cf.GetRecommendations(10, recommendations); // Generate 10 recommendations for specified users. cf.GetRecommendations(10, recommendations, users);
The data matrix is a (user, item, rating) table. Each column in the matrix should have three rows. The first represents the user; the second represents the item; and the third represents the rating. The user and item, while they are in a matrix that holds doubles, should hold integer (or size_t) values. The user and item indices are assumed to start at 0.
Template Parameters:
FactorizerType The type of matrix factorization to use to decompose the rating matrix (a W and H matrix). This must implement the method Apply(arma::sp_mat& data, size_t rank, arma::mat& W, arma::mat& H).
Definition at line 76 of file cf.hpp.
Initialize the CF object. Store a reference to the data that we will be using. There are parameters that can be set; default values are provided for each of them. If the rank is left unset (or is set to 0), a simple density-based heuristic will be used to choose a rank.
Parameters:
data Initial (user, item, rating) matrix.
numUsersForSimilarity Size of the neighborhood.
rank Rank parameter for matrix factorization.
Converts the User, Item, Value Matrix to User-Item Table.
Get the cleaned data matrix.
Definition at line 138 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::cleanedData.
Get the data matrix.
Definition at line 136 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::data.
Sets factorizer for NMF.
Definition at line 124 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::factorizer.
Generates the given number of recommendations for all users.
Parameters:
numRecs Number of Recommendations
recommendations Matrix to save recommendations into.
Generates the given number of recommendations for the specified users.
Parameters:
numRecs Number of Recommendations
recommendations Matrix to save recommendations
users Users for which recommendations are to be generated
Get the Item Matrix.
Definition at line 132 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::h.
Helper function to insert a point into the recommendation matrices.
Parameters:
queryIndex Index of point whose recommendations we are inserting into.
pos Position in list to insert into.
neighbor Index of item being inserted as a recommendation.
value Value of recommendation.
Sets number of users for calculating similarity.
Definition at line 94 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::numUsersForSimilarity, and mlpack::Log::Warn.
Gets number of users for calculating similarity.
Definition at line 106 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::numUsersForSimilarity.
Sets rank parameter for matrix factorization.
Definition at line 112 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::rank.
Gets rank parameter for matrix factorization.
Definition at line 118 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::rank.
Get the Rating Matrix.
Definition at line 134 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::rating.
Returns a string representation of this object.
Get the User Matrix.
Definition at line 130 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::w.
Cleaned data matrix.
Definition at line 181 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::CleanedData().
Initial data matrix.
Definition at line 167 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::Data().
Instantiated factorizer object.
Definition at line 173 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::Factorizer().
Item matrix.
Definition at line 177 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::H().
Number of users for similarity.
Definition at line 169 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::NumUsersForSimilarity().
Rank used for matrix factorization.
Definition at line 171 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::Rank().
Rating matrix.
Definition at line 179 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::Rating().
User matrix.
Definition at line 175 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::W().
Generated automatically by Doxygen for MLPACK from the source code.