| LinearFlow {rsparse} | R 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
vright 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
ranksize of the latent dimension
lambdaregularization parameter
initinitialization of the orthogonal basis.
preprocessidentity()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 applylog1p()to discount large counts.solve_right_singular_vectorstype 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
xinput matrix
...not used at the moment
Method transform()
calculates user embeddings for the new input
Usage
LinearFlow$transform(x, ...)
Arguments
xinput 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
xinput user-item interactions matrix. Model performs matrix facrtorization based only on this matrix
x_trainuser-item interactions matrix. Model recommends items based on this matrix. Usually should be different from 'x' to avoid overfitting
x_testtarget user-item interactions. Model will evaluate predictions against this matrix, 'x_test' should be treated as future interactions.
lambdanumeric 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'.
metrica metric against which model will be evaluated for top-k recommendations. Currently only
map@kandndcg@kare supported (kcan be any integer)not_recommendmatrix 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
deepWhether 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)