R: PureSVD recommender model decompomposition

PureSVD {rsparse} | R Documentation

## PureSVD recommender model decompomposition

### Description

Creates PureSVD recommender model. Solver is based on Soft-SVD which is very similar to truncated SVD but optionally adds regularization based on nuclear norm.

### Super class

`rsparse::MatrixFactorizationRecommender` -> `PureSVD`

### Methods

#### Public methods

- `PureSVD$new()`

- `PureSVD$fit_transform()`

- `PureSVD$transform()`

- `PureSVD$clone()`

Inherited methods

- `rsparse::MatrixFactorizationRecommender$predict()`

#### Method `new()`

create PureSVD model

##### Usage

    PureSVD$new(
      rank = 10L,
      lambda = 0,
      init = NULL,
      preprocess = identity,
      method = c("svd", "impute"),
      ...
    )

##### 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.

`method`

  type of the solver for initialization of the orthogonal basis. Original paper uses SVD. See paper for details.

`...`

  not used at the moment

#### Method `fit_transform()`

performs matrix factorization

##### Usage

    PureSVD$fit_transform(x, n_iter = 100L, convergence_tol = 0.001, ...)

##### Arguments

`x`

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

`n_iter`

  maximum number of iterations

`convergence_tol`

  `numeric = -Inf` defines early stopping strategy. Stops fitting when one of two following conditions will be satisfied: (a) passed all iterations (b) relative change of Frobenious norm of the two consequent solution is less then provided `convergence_tol`.

`...`

  not used at the moment

#### Method `transform()`

calculates user embeddings for the new input

##### Usage

    PureSVD$transform(x, ...)

##### Arguments

`x`

  input matrix

`...`

  not used at the moment

#### Method `clone()`

The objects of this class are cloneable with this method.

##### Usage

    PureSVD$clone(deep = FALSE)

##### Arguments

`deep`

  Whether to make a deep clone.

### 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.4.0 Index]