LinearFlow: Linear-FLow model for one-class collaborative filtering

LinearFlowR Documentation

Linear-FLow model for one-class collaborative filtering

Description

Creates Linear-FLow model described in Practical Linear Models for Large-Scale One-Class Collaborative Filtering. The goal is to find item-item (or user-user) similarity matrix which is low-rank and has small Frobenius norm. Such double regularization allows to better control the generalization error of the model. Idea of the method is somewhat similar to Sparse Linear Methods(SLIM) but scales to large datasets much better.

Super class

rsparse::MatrixFactorizationRecommender -> LinearFlow

Public fields

v

right singular vector of the user-item matrix. Size is n_items * rank. In the paper this matrix is called v

Methods

Public methods

Inherited methods

Method new()

creates Linear-FLow model with rank latent factors.

Usage
LinearFlow$new(
  rank = 8L,
  lambda = 0,
  init = NULL,
  preprocess = identity,
  solve_right_singular_vectors = c("soft_impute", "svd")
)
Arguments
rank

size of the latent dimension

lambda

regularization parameter

init

initialization of the orthogonal basis.

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.

solve_right_singular_vectors

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


Method fit_transform()

performs matrix factorization

Usage
LinearFlow$fit_transform(x, ...)
Arguments
x

input matrix

...

not used at the moment


Method transform()

calculates user embeddings for the new input

Usage
LinearFlow$transform(x, ...)
Arguments
x

input matrix

...

not used at the moment


Method cross_validate_lambda()

performs fast tuning of the parameter 'lambda' with warm re-starts

Usage
LinearFlow$cross_validate_lambda(
  x,
  x_train,
  x_test,
  lambda = "auto@10",
  metric = "map@10",
  not_recommend = x_train,
  ...
)
Arguments
x

input user-item interactions matrix. Model performs matrix facrtorization based only on this matrix

x_train

user-item interactions matrix. Model recommends items based on this matrix. Usually should be different from 'x' to avoid overfitting

x_test

target user-item interactions. Model will evaluate predictions against this matrix, 'x_test' should be treated as future interactions.

lambda

numeric vector - sequaence of regularization parameters. Supports special value like 'auto@10'. This will automatically fine a sequence of lambda of length 10. This is recommended way to check for 'lambda'.

metric

a metric against which model will be evaluated for top-k recommendations. Currently only map@k and ndcg@k are supported (k can be any integer)

not_recommend

matrix same shape as 'x_train'. Specifies which items to not recommend for each user.

...

not used at the moment


Method clone()

The objects of this class are cloneable with this method.

Usage
LinearFlow$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

References

Examples

data("movielens100k")
train = movielens100k[1:900, ]
cv = movielens100k[901:nrow(movielens100k), ]
model = LinearFlow$new(
  rank = 10, lambda = 0,
  solve_right_singular_vectors = "svd"
)
user_emb = model$fit_transform(train)
preds = model$predict(cv, k = 10)

rsparse documentation built on Sept. 12, 2022, 1:06 a.m.