### Example 'adopting' a model from 'recosystem'
library(cmfrec)
library(recosystem)
library(recommenderlab)
library(MatrixExtra)
### Fitting a model with 'recosystem'
data("MovieLense")
X <- as.coo.matrix(MovieLense@data)
r <- Reco()
r$train(data_matrix(X),
out_model = NULL,
opts = list(dim=10, costp_l2=0.1, costq_l2=0.1,
verbose=FALSE, nthread=1))
matrices <- r$output(out_memory(), out_memory())
glob_mean <- as.numeric(r$model$matrices$b)
### Now converting it to CMF
model <- CMF.from.model.matrices(
A=t(matrices$P), B=t(matrices$Q),
glob_mean=glob_mean,
lambda=0.1, scale_lam=TRUE,
implicit=FALSE, nonneg=FALSE,
nthreads=1
)
### Make predictions about new users
factors_single(model, X[10,,drop=TRUE])
topN_new(model,
X=X[10,,drop=TRUE],
exclude=X[10,,drop=TRUE])
Run the code above in your browser using DataLab