This function will swap the users and items in a given matrix factorization model. Since the package functionality is user-centric, it is generally not possible or not efficient to make predictions about items (e.g. recommend users for a given item or calculate new item factors).
This function allows using the same API while avoiding model refitting or deep copies of data by simply swapping the matrices, IDs, and hyperparameters as necessary.
The resulting object can be used with the same functions as the original, such as topN or factors, but any mention of "user" in the functions will now mean "items".
A collective matrix factorization model from this package - see fit_models for details.
Whether to calculate the precomputed matrices for speeding up predictions in new data.
The same model object as before, but with the internal data swapped in order to make predictions about items. If passing 'precompute=TRUE', it will also generate precomputed matrices which can be used to speed up predictions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
library(cmfrec) ### Generate a small random matrix n_users <- 10L n_items <- 8L k <- 3L set.seed(1) X <- matrix(rnorm(n_users*n_items), nrow=n_users) ### Factorize it model <- CMF(X, k=k, verbose=FALSE, nthreads=1L) ### Now swap the users and items model.swapped <- swap.users.and.items(model) ### These will now throw the same result ### (up to numerical precision) item_factors(model, X[, 1]) factors_single(model.swapped, X[, 1]) ### Swapping it again restores the original model.restored <- swap.users.and.items(model.swapped) ### These will throw the same result topN(model, user=2, n=3) topN(model.restored, user=2, n=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.