Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Tensorflow Tfjs Weight Regularization

From Leeroopedia


Knowledge Sources
Domains Deep_Learning, Optimization, Regularization
Last Updated 2026-02-10 06:00 GMT

Overview

Technique that adds penalty terms to the loss function based on weight magnitudes, discouraging overly complex models and reducing overfitting.

Description

Weight regularization constrains the magnitude of model weights during training by adding a penalty term to the loss function. This encourages the model to learn simpler patterns that generalize better to unseen data. TensorFlow.js implements three standard regularizers:

  • L1 (Lasso): Adds the sum of absolute weight values, encouraging sparsity
  • L2 (Ridge): Adds the sum of squared weight values, encouraging small weights
  • L1L2 (Elastic Net): Combines both L1 and L2 penalties

Regularizers are applied per-layer via the kernelRegularizer, biasRegularizer, and activityRegularizer configuration options.

Usage

Apply weight regularization when training models that show signs of overfitting (high training accuracy but low validation accuracy). L2 is the most common default choice. L1 is preferred when feature selection or sparse models are desired.

Theoretical Basis

L1 penalty=λ1i|wi|

L2 penalty=λ2iwi2

Total Loss=Data Loss+L1 penalty+L2 penalty

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment