R: Soft-SVD decompomposition

PureSVD {rsparse} | R Documentation

## Soft-SVD decompomposition

### Description

Creates matrix factorization model based on Soft-SVD. Soft SVD is very similar to truncated SVD with ability do add regularization based on nuclear norm.

### Usage

    PureSVD

### Format

`R6Class` object.

### Usage

For usage details see Methods, Arguments and Examples sections.

      model = PureSVD$new(rank = 10L,
                          lambda = 0,
                          init = NULL,
                          preprocess = identity,
                          ...)
      model$fit_transform(x, n_iter = 5L, ...)
      model$transform(x, ...)
      model$predict(x, k, not_recommend = x, ...)
      model$components

### Methods

`$new(rank = 10L, lambda = 0, init = NULL, preprocess = identity, ... )`

  creates matrix factorization model model with at most `rank` latent factors. If `init` is not null then initializes with provided SVD solution

`$fit_transform(x, n_iter = 5L, ...)`

  fits model to an input user-item matrix. Returns factor matrix for users of size `n_users * rank`

`$transform(x, ...)`

  Calculates user embeddings from given `x` user-item matrix. Result is `n_users * rank` matrix

`$predict(x, k, not_recommend = x, ...)`

  predict `top k` item ids for users `x` (= column names from the matrix passed to `fit_transform()` method). Users features should be defined the same way as they were defined in training data - as sparse matrix of confidence values (implicit feedback) or ratings (explicit feedback). Column names (=item ids) should be in the same order as in the `fit_transform()`.

`$components`

  item factors matrix of size `rank * n_items`

### Arguments

model

  A `PureSVD` model.

x

  An input sparse user-item matrix(of class `dgCMatrix`)

.

rank

  `integer` - maximum number of latent factors

lambda

  `numeric` - regularization parameter for nuclear norm

preprocess

  `function` = `identity()` by default. User spectified function which will be applied to user-item interaction matrix before running matrix factorization (also applied in 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.

not_recommend

  `sparse matrix` or `NULL` - points which items should be excluided from recommendations for a user. By default it excludes previously seen/consumed items.

convergence_tol

  `numeric = -Inf` defines early stopping strategy. We stop fitting when one of two following conditions will be satisfied: (a) we have used all iterations, or (b) relative change of frobenious norm of the two consequent solution is less then provided `convergence_tol`

...

  other arguments. Not used at the moment

### Examples

    data('movielens100k')
    i_train = sample(nrow(movielens100k), 900)
    i_test = setdiff(seq_len(nrow(movielens100k)), i_train)
    train = movielens100k[i_train, ]
    test = movielens100k[i_test, ]
    rank = 32
    lambda = 0
    model = PureSVD$new(rank = rank,  lambda = lambda)
    user_emb = model$fit_transform(sign(test), n_iter = 100, convergence_tol = 0.00001)
    item_emb = model$components
    preds = model$predict(sign(test), k = 1500, not_recommend = NULL)
    mean(ap_k(preds, actual = test))

[Package rsparse version 0.3.3.4 Index]