details_linear_reg_keras: Linear regression via keras/tensorflow

details_linear_reg_kerasR Documentation

Linear regression via keras/tensorflow


This model uses regularized least squares to fit models with numeric outcomes.


For this engine, there is a single mode: regression

Tuning Parameters

This model has one tuning parameter:

  • penalty: Amount of Regularization (type: double, default: 0.0)

For penalty, the amount of regularization is only L2 penalty (i.e., ridge or weight decay).

Translation from parsnip to the original package

linear_reg(penalty = double(1)) %>% 
  set_engine("keras") %>% 
## Linear Regression Model Specification (regression)
## Main Arguments:
##   penalty = double(1)
## Computational engine: keras 
## Model fit template:
## parsnip::keras_mlp(x = missing_arg(), y = missing_arg(), penalty = double(1), 
##     hidden_units = 1, act = "linear")

keras_mlp() is a parsnip wrapper around keras code for neural networks. This model fits a linear regression as a network with a single hidden unit.

Preprocessing requirements

Factor/categorical predictors need to be converted to numeric values (e.g., dummy or indicator variables) for this engine. When using the formula method via fit(), parsnip will convert factor columns to indicators.

Predictors should have the same scale. One way to achieve this is to center and scale each so that each predictor has mean zero and a variance of one.

Case weights

The underlying model implementation does not allow for case weights.


The “Fitting and Predicting with parsnip” article contains examples for linear_reg() with the "keras" engine.


  • Hoerl, A., & Kennard, R. (2000). Ridge Regression: Biased Estimation for Nonorthogonal Problems. Technometrics, 42(1), 80-86.

parsnip documentation built on June 16, 2022, 5:10 p.m.