by rexyai

rexyai /rsparse

Fast and accurate machine learning on sparse matrices - matrix factorizations, regression, classific...

137 Stars 24 Forks Last release: Not found 238 Commits 5 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


Travis-CI Build Status codecov License Project Status

is an R package for statistical learning primarily on sparse matrices - matrix factorizations, factorization machines, out-of-core regression. Many of the implemented algorithms are particularly useful for recommender systems and NLP.

On top of that we provide some optimized routines to work on sparse matrices - multithreaded matrix multiplications and improved support for sparse matrices in CSR format (


We've paid some attention to the implementation details - we try to avoid data copies, utilize multiple threads via OpenMP and use SIMD where appropriate. Package allows to work on datasets with millions of rows and millions of columns.


Please reach us if you need commercial support - [email protected].



  1. Follow the proximally-regularized leader which allows to solve very large linear/logistic regression problems with elastic-net penalty. Solver uses stochastic gradient descent with adaptive learning rates (so can be used for online learning - not necessary to load all data to RAM). See Ad Click Prediction: a View from the Trenches for more examples.
    • Only logistic regerssion implemented at the moment
    • Native format for matrices is CSR -
      . However common R
      ) will be converted automatically.
  2. Factorization Machines supervised learning algorithm which learns second order polynomial interactions in a factorized way. We provide highly optimized SIMD accelerated implementation.

Matrix Factorizations

  1. Vanilla Maximum Margin Matrix Factorization - classic approch for "rating" prediction. See
    class and constructor option
    feedback = "explicit"
    . Original paper which indroduced MMMF could be found here.
  2. Weighted Regularized Matrix Factorization (WRMF) from Collaborative Filtering for Implicit Feedback Datasets. See
    class and constructor option
    feedback = "implicit"
    . We provide 2 solvers:
    1. Exact based on Cholesky Factorization
    2. Approximated based on fixed number of steps of Conjugate Gradient. See details in Applications of the Conjugate Gradient Method for Implicit Feedback Collaborative Filtering and Faster Implicit Matrix Factorization.
  3. Linear-Flow from Practical Linear Models for Large-Scale One-Class Collaborative Filtering. Algorithm looks for factorized low-rank item-item similarity matrix (in some sense it is similar to SLIM)
  4. Fast Truncated SVD and Truncated Soft-SVD via Alternating Least Squares as described in Matrix Completion and Low-Rank SVD via Fast Alternating Least Squares. Works for both sparse and dense matrices. Works on float matrices as well! For certain problems may be even faster than irlba package.
  5. Soft-Impute via fast Alternating Least Squares as described in Matrix Completion and Low-Rank SVD via Fast Alternating Least Squares.
    • with a solution in SVD form
  6. GloVe as described in GloVe: Global Vectors for Word Representation.
    • This is usually used to train word embeddings, but actually also very useful for recommender systems.
  7. Matrix scaling as descibed in EigenRec: Generalizing PureSVD for Effective and Efficient Top-N Recommendations

Optimized matrix operations

  1. multithreaded
  2. multithreaded
  3. natively slice
    matrices (
    ) without converting them to triplet / CSC


Most of the algorithms benefit from OpenMP and many of them could utilize high-performance implementation of BLAS. If you want make maximum out of the package please read the section below carefuly.

It is recommended to:

  1. Use high-performance BLAS (such as OpenBLAS, MKL, Apple Accelerate).
  2. Add proper compiler optimizations in your
    . For example on recent processors (with AVX support) and complier with OpenMP support following lines could be a good option:
    CXX11FLAGS += -O3 -march=native -mavx -fopenmp -ffast-math
    CXXFLAGS   += -O3 -march=native -mavx -fopenmp -ffast-math

If you are on Mac follow instructions here. After installation of

additionally put
line to your
. After that install
in a usual way.


Note that syntax is these posts/slides is not up to date since package was under active development

  1. Slides from DataFest Tbilisi(2017-11-16)
  2. Introduction to matrix factorization with Weighted-ALS algorithm - collaborative filtering for implicit feedback datasets.
  3. Music recommendations using LastFM-360K dataset
    • evaluation metrics for ranking
    • setting up proper cross-validation
    • possible issues with nested parallelism and thread contention
    • making recommendations for new users
    • complimentary item-to-item recommendations
  4. Benchmark against other good implementations

Here is example of

on lastfm360k dataset in comparison with other good implementations:


We follow mlapi conventions.


Generate configure:

autoconf > configure && chmod +x configure

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.