| FTRL | R Documentation |
Creates 'Follow the Regularized Leader' model. Only logistic regression implemented at the moment.
new()creates a model
FTRL$new(
learning_rate = 0.1,
learning_rate_decay = 0.5,
lambda = 0,
l1_ratio = 1,
dropout = 0,
family = c("binomial")
)learning_ratelearning rate
learning_rate_decaylearning rate which controls decay. Please refer to FTRL proximal paper for details. Usually convergense does not heavily depend on this parameter, so default value 0.5 is safe.
lambdaregularization parameter
l1_ratiocontrols L1 vs L2 penalty mixing. 1 = Lasso regression, 0 = Ridge regression. Elastic net is in between
dropoutdropout - percentage of random features to exclude from each sample. Acts as regularization.
familya description of the error distribution and link function to be used in
the model. Only binomial (logistic regression) is implemented at the moment.
partial_fit()fits model to the data
FTRL$partial_fit(x, y, weights = rep(1, length(y)), ...)
xinput 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)
yvector of targets
weightsnumeric 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
FTRL$fit(x, y, weights = rep(1, length(y)), n_iter = 1L, ...)
xinput 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)
yvector of targets
weightsnumeric vector of length 'n_samples'. Defines how to amplify SGD updates for each sample. May be useful for highly unbalanced problems.
n_iternumber of SGD epochs
...not used at the moment
predict()makes predictions based on fitted model
FTRL$predict(x, ...)
xinput matrix
...not used at the moment
coef()returns coefficients of the regression model
FTRL$coef()
clone()The objects of this class are cloneable with this method.
FTRL$clone(deep = FALSE)
deepWhether to make a deep clone.
library(rsparse)
library(Matrix)
i = sample(1000, 1000 * 100, TRUE)
j = sample(1000, 1000 * 100, TRUE)
y = sample(c(0, 1), 1000, TRUE)
x = sample(c(-1, 1), 1000 * 100, TRUE)
odd = seq(1, 99, 2)
x[i %in% which(y == 1) & j %in% odd] = 1
x = sparseMatrix(i = i, j = j, x = x, dims = c(1000, 1000), repr="R")
ftrl = FTRL$new(learning_rate = 0.01, learning_rate_decay = 0.1,
lambda = 10, l1_ratio = 1, dropout = 0)
ftrl$partial_fit(x, y)
w = ftrl$coef()
head(w)
sum(w != 0)
p = ftrl$predict(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.