PureSVD | R Documentation |
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.
rsparse::MatrixFactorizationRecommender
-> PureSVD
new()
create PureSVD model
PureSVD$new( rank = 10L, lambda = 0, init = NULL, preprocess = identity, method = c("svd", "impute"), ... )
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
fit_transform()
performs matrix factorization
PureSVD$fit_transform(x, n_iter = 100L, convergence_tol = 0.001, ...)
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
transform()
calculates user embeddings for the new input
PureSVD$transform(x, ...)
x
input matrix
...
not used at the moment
clone()
The objects of this class are cloneable with this method.
PureSVD$clone(deep = FALSE)
deep
Whether to make a deep clone.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.