Lasso Regularization (L1 Regularization) › Formula
Machine Learning from ScratchAll chapters Lasso Regularization (L1 Regularization) › FormulaOne section · Sections in this chapter2 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
LASSO regularization is formulated as a minimization optimization problem. The goal is to find the set of coefficients that fit the data well (by minimizing the sum of squared errors) while keeping the model simple by penalizing large coefficients. In other words, LASSO seeks to minimize a loss function that combines the usual error term with an additional penalty based on the absolute values of the coefficients. The formula for this optimization problem is:
where:
- : regularization parameter (controls the strength of the penalty)
- : number of features in the model
- : coefficient for the -th feature (where )
- : absolute value of the -th coefficient (ensures non-negative penalty)
- : sum of squared errors between predicted and actual values
The regularization parameter controls the strength of the regularization. A larger results in more shrinkage of the coefficients, and a smaller results in less shrinkage.
Written as a minimization problem, it is:
This is read as: "minimize the sum of squared errors plus the regularization penalty, with respect to the coefficients". The fully written-out formula is:
where:
- : number of observations in the dataset
- : actual target value for observation
- : intercept term (typically not penalized)
- : value of feature for observation
- : regularization parameter
- : number of features
The left side of the equations, the sum of squared errors (SSE), should look familiar from the previous section on ordinary least squares (OLS). The right side is the regularization penalty. However, unlike OLS, LASSO requires us to minimize the SSE plus the regularization penalty. OLS allows us to directly compute the optimal coefficients using a closed-form solution and vector algebra, but LASSO does not have this property.
This means we need to use optimization techniques to find the best coefficients, rather than relying on a simple formula. In other words, we are using iterative optimization methods to find the coefficients that minimize the combined objective function.
We're about to dive deep and cover several important concepts at once, including partial derivatives, the chain rule, and function minimization. While this may seem like a lot to take in, mastering these ideas here will make understanding future topics much easier. I've taken the time to explain everything in detail to help you build a strong, intuitive understanding. Take as much time as you need to understand this section. It'll be worth it.