# tfl.configs.RegularizerConfig

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L843-L935) |

Regularizer configuration for TFL canned estimators.

    tfl.configs.RegularizerConfig(
        name, l1=0.0, l2=0.0
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [TF Lattice Premade Models](https://www.tensorflow.org/lattice/tutorials/premade_models) - [Shape Constraints with Tensorflow Lattice](https://www.tensorflow.org/lattice/tutorials/shape_constraints) |

Regularizers can either be applied to specific features, or can be applied
globally to all features or lattices.

- **Calibrator regularizers:**

  These regularizers are applied to PWL calibration layers.
  - `'calib_laplacian'`: Creates an instance of [`tfl.pwl_calibration_layer.LaplacianRegularizer`](https://www.tensorflow.org/lattice/api_docs/python/tfl/pwl_calibration_layer/LaplacianRegularizer). A calibrator laplacian regularizer penalizes the changes in the output and results in a *flatter
    calibration function*.
  - `'calib_hessian'`: Creates an instance of [`tfl.pwl_calibration_layer.HessianRegularizer`](https://www.tensorflow.org/lattice/api_docs/python/tfl/pwl_calibration_layer/HessianRegularizer). A calibrator hessian regularizer penalizes changes in the slope, resulting in a *more linear
    calibration*.
  - `'calib_wrinkle'`: Creates an instance of [`tfl.pwl_calibration_layer.WrinkleRegularizer`](https://www.tensorflow.org/lattice/api_docs/python/tfl/pwl_calibration_layer/WrinkleRegularizer). A calibrator wrinkle regularizer penalizes the second derivative, resulting in a smoother function with *less changes in the curvature*.
- **Lattice regularizers:**

  These regularizers are applied to lattice layers.
  - `'laplacian'`: Creates an instance of [`tfl.lattice_layer.LaplacianRegularizer`](https://www.tensorflow.org/lattice/api_docs/python/tfl/lattice_layer/LaplacianRegularizer). Laplacian regularizers penalize the difference between adjacent vertices in multi-cell lattice, resulting in a *flatter lattice function*.
  - `'torsion'`: Creates an instance of [`tfl.lattice_layer.TorsionRegularizer`](https://www.tensorflow.org/lattice/api_docs/python/tfl/lattice_layer/TorsionRegularizer). Torsion regularizers penalizes how much the lattice function twists from side-to-side, a non-linear interactions in each 2 x 2 cell. Using this regularization results in a *more linear lattice function*.

#### Examples:

    model_config = tfl.configs.CalibratedLatticeConfig(
        feature_configs=[
            tfl.configs.FeatureConfig(
                name='age',
                lattice_size=3,
                # Per feature regularization.
                regularizer_configs=[
                    tfl.configs.RegularizerConfig(name='calib_hessian', l2=1e-4),
                ],
            ),
            tfl.configs.FeatureConfig(
                name='thal',
                # Partial monotonicity:
                # output(normal) <= output(fixed)
                # output(normal) <= output(reversible)
                monotonicity=[('normal', 'fixed'), ('normal', 'reversible')],
            ),
        ],
        # Global regularizers
        regularizer_configs=[
            # Torsion regularizer applied to the lattice to make it more linear.
            configs.RegularizerConfig(name='torsion', l2=1e-4),
            # Globally defined calibration regularizer is applied to all features.
            configs.RegularizerConfig(name='calib_hessian', l2=1e-4),
        ])
    feature_analysis_input_fn = create_input_fn(num_epochs=1, ...)
    train_input_fn = create_input_fn(num_epochs=100, ...)
    estimator = tfl.estimators.CannedClassifier(
        feature_columns=feature_columns,
        model_config=model_config,
        feature_analysis_input_fn=feature_analysis_input_fn)
    estimator.train(input_fn=train_input_fn)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `name` | The name of the regularizer. |
| `l1` | l1 regularization amount. |
| `l2` | l2 regularization amount. |

<br />

## Methods

### `deserialize_nested_configs`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L124-L158)

    @classmethod
    deserialize_nested_configs(
        config, custom_objects=None
    )

Returns a deserialized configuration dictionary.

### `from_config`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L932-L935)

    @classmethod
    from_config(
        config, custom_objects=None
    )

### `get_config`

[View source](https://github.com/tensorflow/lattice/blob/v2.1.1/tensorflow_lattice/python/configs.py#L93-L122)

    get_config()

Returns a configuration dictionary.