LIBMF Rust
LIBMF - large-scale sparse matrix factorization - for Rust
Installation
Add this line to your application’s Cargo.toml under [dependencies]:
= { = "0.1" }
Getting Started
Prep your data in the format row_index, column_index, value
let mut data = new;
data.push;
data.push;
data.push;
Create a model
let mut model = new;
model.fit;
Make predictions
model.predict;
Get the latent factors (these approximate the training matrix)
model.p_factors;
model.q_factors;
Get the bias (average of all elements in the training matrix)
model.bias;
Save the model to a file
model.save;
Load the model from a file
let model = load;
Pass a validation set
model.fit_eval;
Cross-Validation
Perform cross-validation
model.cv;
Parameters
Set parameters - default values below
model.loss = 0; // loss function
model.factors = 8; // number of latent factors
model.threads = 12; // number of threads used
model.bins = 25; // number of bins
model.iterations = 20; // number of iterations
model.lambda_p1 = 0; // coefficient of L1-norm regularization on P
model.lambda_p2 = 0.1; // coefficient of L2-norm regularization on P
model.lambda_q1 = 0; // coefficient of L1-norm regularization on Q
model.lambda_q2 = 0.1; // coefficient of L2-norm regularization on Q
model.learning_rate = 0.1; // learning rate
model.alpha = 0.1; // importance of negative entries
model.c = 0.0001; // desired value of negative entries
model.nmf = false; // perform non-negative MF (NMF)
model.quiet = false; // no outputs to stdout
Loss Functions
For real-valued matrix factorization
- 0 - squared error (L2-norm)
- 1 - absolute error (L1-norm)
- 2 - generalized KL-divergence
For binary matrix factorization
- 5 - logarithmic error
- 6 - squared hinge loss
- 7 - hinge loss
For one-class matrix factorization
- 10 - row-oriented pair-wise logarithmic loss
- 11 - column-oriented pair-wise logarithmic loss
- 12 - squared error (L2-norm)
Reference
Specify the initial capacity for a matrix
let mut data = with_capacity;
Resources
History
View the changelog
Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development: