FactorizationMachine | R Documentation |
Creates second order Factorization Machines model
new()
creates Creates second order Factorization Machines model
FactorizationMachine$new( learning_rate_w = 0.2, rank = 4, lambda_w = 0, lambda_v = 0, family = c("binomial", "gaussian"), intercept = TRUE, learning_rate_v = learning_rate_w )
learning_rate_w
learning rate for features intercations
rank
dimension of the latent dimensions which models features interactions
lambda_w
regularization for features interactions
lambda_v
regularization for features
family
one of "binomial", "gaussian"
intercept
logical, indicates whether or not include intecept to the model
learning_rate_v
learning rate for features
partial_fit()
fits/updates model
FactorizationMachine$partial_fit(x, y, weights = rep(1, length(y)), ...)
x
input sparse matrix. Native format is Matrix::RsparseMatrix
.
If x
is in different format, model will try to convert it to RsparseMatrix
with as(x, "RsparseMatrix")
. Dimensions should be (n_samples, n_features)
y
vector of targets
weights
numeric vector of length 'n_samples'. Defines how to amplify SGD updates for each sample. May be useful for highly unbalanced problems.
...
not used at the moment
fit()
shorthand for applying 'partial_fit' 'n_iter' times
FactorizationMachine$fit(x, y, weights = rep(1, length(y)), n_iter = 1L, ...)
x
input sparse matrix. Native format is Matrix::RsparseMatrix
.
If x
is in different format, model will try to convert it to RsparseMatrix
with as(x, "RsparseMatrix")
. Dimensions should be (n_samples, n_features)
y
vector of targets
weights
numeric vector of length 'n_samples'. Defines how to amplify SGD updates for each sample. May be useful for highly unbalanced problems.
n_iter
number of SGD epochs
...
not used at the moment
predict()
makes predictions based on fitted model
FactorizationMachine$predict(x, ...)
x
input sparse matrix of shape (n_samples, n_featires)
...
not used at the moment
clone()
The objects of this class are cloneable with this method.
FactorizationMachine$clone(deep = FALSE)
deep
Whether to make a deep clone.
# Factorization Machines can fit XOR function!
x = rbind(
c(0, 0),
c(0, 1),
c(1, 0),
c(1, 1)
)
y = c(0, 1, 1, 0)
x = as(x, "RsparseMatrix")
fm = FactorizationMachine$new(learning_rate_w = 10, rank = 2, lambda_w = 0,
lambda_v = 0, family = 'binomial', intercept = TRUE)
res = fm$fit(x, y, n_iter = 100)
preds = fm$predict(x)
all(preds[c(1, 4)] < 0.01)
all(preds[c(2, 3)] > 0.99)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.