FTRL: Creates FTRL proximal model.

Description Usage Format Fields Usage Methods Arguments Examples

Description

Creates 'Follow the Regularized Leader' model. Only logistic regression implemented at the moment.

Usage

1

Format

R6Class object.

Fields

verbose

logical = TRUE whether to display training inforamtion

Usage

For usage details see Methods, Arguments and Examples sections.

1
2
3
4
ftrl = FTRL$new(alpha = 0.1, beta = 0.5, lambda = 0, l1_ratio = 1, dropout = 0, family = "binomial")
ftrl$partial_fit(X, y, n_threads  = 0, ...)
ftrl$predict(X, n_threads  = 0, ...)
ftrl$coef()

Methods

FTRL$new(alpha = 0.1, beta = 0.5, lambda = 0, l1_ratio = 1, dropout = 0, family = "binomial")

Constructor for FTRL model. For description of arguments see Arguments section.

$partial_fit(X, y, n_threads = 0, ...)

fits/updates model given input matrix X and target vector y. X shape = (n_samples, n_features)

$predict(X, n_threads = 0, ...)

predicts output X

$coef()

return coefficients of the regression model

$dump()

create dump of the model (actually list with current model parameters)

$load(x)

load/initialize model from dump)

Arguments

ftrl

FTRL object

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") call

alpha

learning rate

beta

learning rate which controls decay. Please refer to FTRL paper for details. Usually convergense does not heavily depend on this parameter, so default value 0.5 is safe.

lambda

regularization parameter

l1_ratio

controls L1 vs L2 penalty mixing. 1 = Lasso regression, 0 = Ridge regression. Elastic net is in between.

dropout

dropout - percentage of random features to exclude from each sample. Kind of regularization.

n_features

number of features in model (number of columns in expected model matrix)

family

family of generalized linear model to solve. Only binomial (or logistic regression) supported at the moment.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(FTRL)
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
m = sparseMatrix(i = i, j = j, x = x, dims = c(1000, 1000), giveCsparse = FALSE)
X = as(m, "RsparseMatrix")

ftrl = FTRL$new(alpha = 0.01, beta = 0.1, lambda = 10, l1_ratio = 1, dropout = 0)
ftrl$partial_fit(X, y, n_threads = 8)

w = ftrl$coef()
head(w)
sum(w != 0)
p = ftrl$predict(m)

dselivanov/FTRL documentation built on May 15, 2019, 2:59 p.m.