MLPACK
1.0.11
|
This class implements Collaborative Filtering (CF). More...
Public Member Functions | |
CF (arma::mat &data, const size_t numUsersForSimilarity=5, const size_t rank=0) | |
Initialize the CF object. More... | |
const arma::sp_mat & | CleanedData () const |
Get the cleaned data matrix. More... | |
const arma::mat & | Data () const |
Get the data matrix. More... | |
void | Factorizer (const FactorizerType &f) |
Sets factorizer for NMF. More... | |
void | GetRecommendations (const size_t numRecs, arma::Mat< size_t > &recommendations) |
Generates the given number of recommendations for all users. More... | |
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. More... | |
const arma::mat & | H () const |
Get the Item Matrix. More... | |
void | NumUsersForSimilarity (const size_t num) |
Sets number of users for calculating similarity. More... | |
size_t | NumUsersForSimilarity () const |
Gets number of users for calculating similarity. More... | |
void | Rank (const size_t rankValue) |
Sets rank parameter for matrix factorization. More... | |
size_t | Rank () const |
Gets rank parameter for matrix factorization. More... | |
const arma::mat & | Rating () const |
Get the Rating Matrix. More... | |
std::string | ToString () const |
Returns a string representation of this object. More... | |
const arma::mat & | W () const |
Get the User Matrix. More... | |
Private Member Functions | |
void | CleanData () |
Converts the User, Item, Value Matrix to User-Item Table. More... | |
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. More... | |
Private Attributes | |
arma::sp_mat | cleanedData |
Cleaned data matrix. More... | |
arma::mat | data |
Initial data matrix. More... | |
FactorizerType | factorizer |
Instantiated factorizer object. More... | |
arma::mat | h |
Item matrix. More... | |
size_t | numUsersForSimilarity |
Number of users for similarity. More... | |
size_t | rank |
Rank used for matrix factorization. More... | |
arma::mat | rating |
Rating matrix. More... | |
arma::mat | w |
User matrix. More... | |
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.
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.
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). |
mlpack::cf::CF< FactorizerType >::CF | ( | arma::mat & | data, |
const size_t | numUsersForSimilarity = 5 , |
||
const size_t | rank = 0 |
||
) |
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.
data | Initial (user, item, rating) matrix. |
numUsersForSimilarity | Size of the neighborhood. |
rank | Rank parameter for matrix factorization. |
|
private |
Converts the User, Item, Value Matrix to User-Item Table.
|
inline |
Get the cleaned data matrix.
Definition at line 138 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::cleanedData, mlpack::cf::CF< FactorizerType >::GetRecommendations(), and mlpack::cf::CF< FactorizerType >::ToString().
|
inline |
Get the data matrix.
Definition at line 136 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::data.
|
inline |
Sets factorizer for NMF.
Definition at line 124 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::factorizer.
void mlpack::cf::CF< FactorizerType >::GetRecommendations | ( | const size_t | numRecs, |
arma::Mat< size_t > & | recommendations | ||
) |
Generates the given number of recommendations for all users.
numRecs | Number of Recommendations |
recommendations | Matrix to save recommendations into. |
Referenced by mlpack::cf::CF< FactorizerType >::CleanedData().
void mlpack::cf::CF< FactorizerType >::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.
numRecs | Number of Recommendations |
recommendations | Matrix to save recommendations |
users | Users for which recommendations are to be generated |
|
inline |
Get the Item Matrix.
Definition at line 132 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::h.
|
private |
Helper function to insert a point into the recommendation matrices.
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. |
|
inline |
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.
|
inline |
Gets number of users for calculating similarity.
Definition at line 106 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::numUsersForSimilarity.
|
inline |
Sets rank parameter for matrix factorization.
Definition at line 112 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::rank.
|
inline |
Gets rank parameter for matrix factorization.
Definition at line 118 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::rank.
|
inline |
Get the Rating Matrix.
Definition at line 134 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::rating.
std::string mlpack::cf::CF< FactorizerType >::ToString | ( | ) | const |
Returns a string representation of this object.
Referenced by mlpack::cf::CF< FactorizerType >::CleanedData().
|
inline |
Get the User Matrix.
Definition at line 130 of file cf.hpp.
References mlpack::cf::CF< FactorizerType >::w.
|
private |
Cleaned data matrix.
Definition at line 181 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::CleanedData().
|
private |
Initial data matrix.
Definition at line 167 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::Data().
|
private |
Instantiated factorizer object.
Definition at line 173 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::Factorizer().
|
private |
Item matrix.
Definition at line 177 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::H().
|
private |
Number of users for similarity.
Definition at line 169 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::NumUsersForSimilarity().
|
private |
Rank used for matrix factorization.
Definition at line 171 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::Rank().
|
private |
Rating matrix.
Definition at line 179 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::Rating().
|
private |
User matrix.
Definition at line 175 of file cf.hpp.
Referenced by mlpack::cf::CF< FactorizerType >::W().