| LinearFlow | R Documentation |
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.
rsparse::MatrixFactorizationRecommender -> LinearFlow
vright singular vector of the user-item matrix. Size is n_items * rank.
In the paper this matrix is called v
new()creates Linear-FLow model with rank latent factors.
LinearFlow$new(
rank = 8L,
lambda = 0,
init = NULL,
preprocess = identity,
solve_right_singular_vectors = c("soft_impute", "svd")
)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 apply log1p() 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.
fit_transform()performs matrix factorization
LinearFlow$fit_transform(x, ...)
xinput matrix
...not used at the moment
transform()calculates user embeddings for the new input
LinearFlow$transform(x, ...)
xinput matrix
...not used at the moment
cross_validate_lambda()performs fast tuning of the parameter 'lambda' with warm re-starts
LinearFlow$cross_validate_lambda( x, x_train, x_test, lambda = "auto@10", metric = "map@10", not_recommend = x_train, ... )
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@k and ndcg@k are supported (k can be any integer)
not_recommendmatrix same shape as 'x_train'. Specifies which items to not recommend for each user.
...not used at the moment
clone()The objects of this class are cloneable with this method.
LinearFlow$clone(deep = FALSE)
deepWhether to make a deep clone.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.