>>> from mlpack import cf
This program performs collaborative filtering (CF) on the given dataset. Given a list of user, item and preferences (the 'training' parameter), the program will perform a matrix decomposition and then can perform a series of actions related to collaborative filtering. Alternately, the program can load an existing saved CF model with the 'input_model' parameter and then use that model to provide recommendations or predict values.
The input matrix should be a 3-dimensional matrix of ratings, where the first dimension is the user, the second dimension is the item, and the third dimension is that user's rating of that item. Both the users and items should be numeric indices, not names. The indices are assumed to start from 0.
A set of query users for which recommendations can be generated may be specified with the 'query' parameter; alternately, recommendations may be generated for every user in the dataset by specifying the 'all_user_recommendations' parameter. In addition, the number of recommendations per user to generate can be specified with the 'recommendations' parameter, and the number of similar users (the size of the neighborhood) to be considered when generating recommendations can be specified with the 'neighborhood' parameter.
For performing the matrix decomposition, the following optimization algorithms can be specified via the 'algorithm' parameter:
- 'RegSVD' -- Regularized SVD using a SGD optimizer
- 'NMF' -- Non-negative matrix factorization with alternating least squares update rules
- 'BatchSVD' -- SVD batch learning
- 'SVDIncompleteIncremental' -- SVD incomplete incremental learning
- 'SVDCompleteIncremental' -- SVD complete incremental learning
A trained model may be saved to with the 'output_model' output parameter.
To train a CF model on a dataset 'training_set' using NMF for decomposition and saving the trained model to 'model', one could call:
>>> output = cf(training=training_set, algorithm='NMF')
>>> model = output['output_model']
Then, to use this model to generate recommendations for the list of users in the query set 'users', storing 5 recommendations in 'recommendations', one could call
>>> output = cf(input_model=model, query=users, recommendations=5)
>>> recommendations = output['output']
- algorithm (string): Algorithm used for matrix factorization. Default value NMF.
- all_user_recommendations (bool): Generate recommendations for all users.
- copy_all_inputs (bool): If specified, all input parameters will be deep copied before the method is run. This is useful for debugging problems where the input parameters are being modified by the algorithm, but can slow down the code.
- input_model (mlpack.CFTypeType): Trained CF model to load.
- iteration_only_termination (bool): Terminate only when the maximum number of iterations is reached.
- max_iterations (int): Maximum number of iterations. If set to zero, there is no limit on the number of iterations. Default value 1000.
- min_residue (float): Residue required to terminate the factorization (lower values generally mean better fits). Default value 1e-05.
- neighborhood (int): Size of the neighborhood of similar users to consider for each query user. Default value 5.
- query (numpy matrix or arraylike, int/long dtype): List of query users for which recommendations should be generated.
- rank (int): Rank of decomposed matrices (if 0, a heuristic is used to estimate the rank). Default value 0.
- recommendations (int): Number of recommendations to generate for each query user. Default value 5.
- seed (int): Set the random seed (0 uses std::time(NULL)). Default value 0.
- test (numpy matrix or arraylike, float dtype): Test set to calculate RMSE on.
- training (numpy matrix or arraylike, float dtype): Input dataset to perform CF on.
- verbose (bool): Display informational messages and the full list of parameters and timers at the end of execution.
The return value from the binding is a dict containing the following elements:
- output (numpy matrix, int dtype): Matrix that will store output recommendations.
- output_model (mlpack.CFTypeType): Output for trained CF model.