R: Weighted Regularized Matrix Facrtorization for collaborative...

WRMF {rsparse} | R Documentation

## Weighted Regularized Matrix Facrtorization for collaborative filtering

### Description

Creates matrix factorization model which could be solved with Alternating Least Squares (Weighted ALS for implicit feedback). For implicit feedback see "Collaborative Filtering for Implicit Feedback Datasets" (Hu, Koren, Volinsky). For explicit feedback model is classic model for rating matrix decomposition with MSE error (without biases at the moment). These two algorithms are proven to work well in recommender systems.

### Super class

`rsparse::MatrixFactorizationRecommender` -> `WRMF`

### Methods

#### Public methods

- `WRMF$new()`

- `WRMF$fit_transform()`

- `WRMF$transform()`

- `WRMF$clone()`

Inherited methods

- `rsparse::MatrixFactorizationRecommender$predict()`

#### Method `new()`

creates WRMF model

##### Usage

    WRMF$new(
      rank = 10L,
      lambda = 0,
      init = NULL,
      preprocess = identity,
      feedback = c("implicit", "explicit"),
      non_negative = FALSE,
      solver = c("conjugate_gradient", "cholesky"),
      cg_steps = 3L,
      precision = c("double", "float"),
      ...
    )

##### Arguments

`rank`

  size of the latent dimension

`lambda`

  regularization parameter

`init`

  initialization of item embeddings

`preprocess`

  `identity()` by default. User spectified function which will be applied to user-item interaction matrix before running matrix factorization (also applied during inference time before making predictions). For example we may want to normalize each row of user-item matrix to have 1 norm. Or apply `log1p()` to discount large counts. This corresponds to the "confidence" function from "Collaborative Filtering for Implicit Feedback Datasets" paper.

`feedback`

  `character` - feedback type - one of `c("implicit", "explicit")`

`non_negative`

  logical, whether to perform non-negative factorization

`solver`

  `character` - solver for "implicit feedback" problem. One of `c("conjugate_gradient", "cholesky")`. Usually approximate `"conjugate_gradient"` is significantly faster and solution is on par with `"cholesky"`

`cg_steps`

  `integer > 0` - max number of internal steps in conjugate gradient (if "conjugate_gradient" solver used). `cg_steps = 3` by default. Controls precision of linear equation solution at the each ALS step. Usually no need to tune this parameter

`precision`

  one of `c("double", "float")`. Should embeeding matrices be numeric or float (from `float` package). The latter is usually 2x faster and consumes less RAM. BUT `float` matrices are not "base" objects. Use carefully.

`...`

  not used at the moment

#### Method `fit_transform()`

fits the model

##### Usage

    WRMF$fit_transform(x, n_iter = 10L, convergence_tol = 0.005, ...)

##### Arguments

`x`

  input matrix (preferably matrix in CSC format -'CsparseMatrix'

`n_iter`

  max number of ALS iterations

`convergence_tol`

  convergence tolerance checked between iterations

`...`

  not used at the moment

#### Method `transform()`

create user embeddings for new input

##### Usage

    WRMF$transform(x, ...)

##### Arguments

`x`

  user-item iteraction matrix

`...`

  not used at the moment

#### Method `clone()`

The objects of this class are cloneable with this method.

##### Usage

    WRMF$clone(deep = FALSE)

##### Arguments

`deep`

  Whether to make a deep clone.

### References

- https://math.stackexchange.com/questions/1072451/analytic-solution-for-matrix-factorization-using-alternating-least-squares/1073170#1073170

- http://activisiongamescience.github.io/2016/01/11/Implicit-Recommender-Systems-Biased-Matrix-Factorization/

- http://datamusing.info/blog/2015/01/07/implicit-feedback-and-collaborative-filtering/

- https://jessesw.com/Rec-System/

- http://danielnee.com/2016/09/collaborative-filtering-using-alternating-least-squares/

- http://www.benfrederickson.com/matrix-factorization/

- http://www.benfrederickson.com/fast-implicit-matrix-factorization/

### Examples

    data('movielens100k')
    train = movielens100k[1:900, ]
    cv = movielens100k[901:nrow(movielens100k), ]
    model = WRMF$new(rank = 5,  lambda = 0, feedback = 'implicit')
    user_emb = model$fit_transform(train, n_iter = 5, convergence_tol = -1)
    item_emb = model$components
    preds = model$predict(cv, k = 10, not_recommend = cv)

[Package rsparse version 0.4.0 Index]