Description Usage Arguments Details Value Methods (by class) References Examples
libFM factorization machines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | libFM(train, test, ...)
## S3 method for class 'data.frame'
libFM(train, test, formula, validation, grouping, ...)
## S3 method for class 'matrix'
libFM(train, test, y_train, y_test, validation, y_validation,
grouping, ...)
## S3 method for class 'dgCMatrix'
libFM(train, test, y_train, y_test, validation,
y_validation, grouping, ...)
## Default S3 method:
libFM(train, test, global_bias = TRUE,
variable_bias = TRUE, dim = 8, task = c("c", "r"), method = c("mcmc",
"sgd", "als", "sgda"), init_stdev = 0.1, regular = c(0, 0, 0),
learn_rate = 0.1, validation, verbosity = 0, iter = 100, exe_loc,
grouping, seed = NULL, ...)
|
train |
training data.frame, (sparse) matrix, or character vector |
test |
testing data.frame, (sparse) matrix, or character vector |
... |
other, unused, arguments |
formula |
formula of covariates included |
validation |
validation data.frame, (sparse) matrix, or character vector used for adaptive SGD |
grouping |
logical scalar or integer vector. See details |
y_train, y_test, y_validation |
numeric vectors of responses when train, test, and validation are matrices |
global_bias |
whether to include an overall/global bias term |
variable_bias |
whether to include variable main effects/biases |
dim |
dimension of the two-way interaction |
task |
classifcation or regression |
method |
learning method |
init_stdev |
standard deviation used for initialization of 2-way factors |
regular |
length 3 vector of regularization parameters for global bias, variable biases, and interactions, respectively. Used with SGD and ALS |
learn_rate |
learning rate used for SGD and adaptive SGD |
verbosity |
how much feedback to give |
iter |
number of iterations |
exe_loc |
location of libFM.exe executable (if not in the PATH) |
seed |
integer value of the seed for the random number generator. Only implemented on version 1.4.2 or greater |
See the libFM manual, http://www.libfm.org/libfm-1.42.manual.pdf, for details on the parameters.
For grouping, if specifying model with a formula, this should be a logical of whether to group levels of a factor variable. If set to TRUE, each variable in the formula gets its own group. If specifying the model with a design matrix, this should be an integer vector of the same length as the number of columns in the design matix, where each integer specifies the group which the variable belongs to.
If the function is not working, make sure that the directory is in the PATH
by running Sys.getenv('PATH')
. It is assumed that the executable is named
libFM
. You can verify that the executable is being found and works by
running system("libFM -help")
in the R console. See the README on
https://github.com/andland/libFMexe for some more information on installation.
A vector of the predicted values/probabilities
data.frame
:
matrix
:
dgCMatrix
:
default
:
Steffen Rendle (2012): Factorization Machines with libFM, in ACM Trans. Intell. Syst. Technol., 3(3), May.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ## Not run:
data(movie_lens)
train_rows = sample.int(nrow(movie_lens), nrow(movie_lens) * 2 / 3)
train = movie_lens[train_rows, ]
test = movie_lens[-train_rows, ]
predFM = libFM(train, test, Rating ~ User + Movie,
task = "r", dim = 10, iter = 500)
mean((predFM - test$Rating)^2)
# the same can be done slightly more slowly with sparse matrices
train_mat = Matrix::sparse.model.matrix(Rating ~ User + Movie - 1, train)
test_mat = Matrix::sparse.model.matrix(Rating ~ User + Movie - 1, test)
predFM = libFM(train_mat, test_mat, train$Rating, test$Rating,
task = "r", dim = 10, iter = 500)
mean((predFM - test$Rating)^2)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.