Learn R Programming

dnn (version 0.0.6)

deepGLM: Deep learning for the generalized linear model

Description

Fit generalized linear models (Gaussian, Binomial and Poisson) using deep learning neural network (DNN). The glm formula is specified by giving a symbolic description of the predictor and a description of the error distribution.

Usage

deepGlm(formula, model, family = c("gaussian", "binomial",
        "poisson"), data, epochs = 200, lr_rate = 1e-04,
         batch_size = 64, alpha = 0.7, lambda = 1, verbose = 0,
         weights = NULL, ...)

Value

An object of class "deepGlm" is returned. The deepGlm object contains the following list components:

x

Covariates for glm model

y

Object for glm model

model

dnn model

predictor

predictor score mu = f(x)

risk

risk score = exp(predictor)

Arguments

formula

a formula expression as for other regression models. The response is usually an object for glm response variable. See the documentation for 'glm', 'lm' and 'formula' for details.

model

a deep neural network model, created by function dNNmodel().

family

a description of the error distribution and link function to be used in the model. This can be either a character string of 'gaussian', 'binomial', or 'poisson', naming a family function, or result of a call to a family function (See 'family' for details of family functions).)

data

a data.frame in which to interpret the variables named in the formula.

epochs

number of deep learning epochs, default is 200.

batch_size

batch size, default is 64. 'NaN' may be generated if batch size is too small and there is not event in a batch.

lr_rate

learning rate for the gradient descent algorithm, default is lr_rate = 1e-04.

weights

an optional vector of 'prior weights' to be used in the fitting process. Should be NULL or a numeric vector.

alpha

momentum rate for the gradient descent method, alpha takes value in [0, 1), default is alpha = 0.70.

lambda

L2 regularization parameter for deep learning.

verbose

verbose = 1 for print out verbose during the model fit, 0 for not print.

...

optional arguments

Author

Chen, B. E.

Details

See dNNmodel for details on how to specify a deep learning model.

The following parameters in 'dnnControl' will be used to control the model fit process.

'epochs': number of deep learning epochs, default is 30.

'verbose': verbose = 1 for print out verbose during the model fit, 0 for not print.

When the variance for covariance matrix X is too large, please use xbar = scale(x) to standardize X.

References

Chollet, F. and Allaire J. J. (2017). Deep learning with R. Manning.

See Also

deepAFT, dNNmodel, predict.deepGlm, print.deepSurv, glm

Examples

Run this code
## Example for deep learning for glm models
  set.seed(101)
### define model layers
  model = dNNmodel(units = c(4, 3, 1), activation = c("elu", "sigmoid", "sigmoid"), 
                   input_shape = 3)
  x = matrix(runif(15), nrow = 5, ncol = 3)
  y = exp(x[, 1] + rnorm(5))
  
  fit = deepGlm(y ~ x, model, family = "gaussian") 

Run the code above in your browser using DataLab