Why the Same Penalty Number Can Mean Different Things
A penalty parameter is meaningful only in relation to the scale of the loss it penalizes. One implementation may minimize the sum of the observations’ losses, while another minimizes their average. These objectives can produce exactly the same fit, but only when their penalty parameters are rescaled consistently. If the same numerical penalty is used in both, the relative influence of the penalty is generally different.
This matters when comparing results from software packages, implementations, or data sets of different sizes. A reported value such as \(\lambda=0.1\) does not, on its own, identify how strongly coefficients were penalized. The objective function—including its loss normalization and penalty definition—must also be known.
Two Objective Conventions
Let \(y_i\) be the response for observation \(i\), \(x_i\) its predictor vector, and \(\beta\) the coefficient vector. Write \(\ell_i(\beta)\) for the loss contributed by observation \(i\). For example, squared-error regression may use \(\ell_i(\beta)=\tfrac12(y_i-x_i^\mathsf{T}\beta)^2\), while logistic regression can use the negative log-likelihood contribution for observation \(i\). Let \(P(\beta)\) be a penalty, such as the lasso penalty \(\|\beta\|_1=\sum_j|\beta_j|\). In the formulations below, the intercept, if included, is not penalized.
The factor \(1/n\) changes the scale of the loss but not the definition of \(P\). Thus, to compare these objectives, we need to account for that factor in the penalty too. The relationship is an algebraic one; it does not require a probability model or an assumption that the observations are independent. Statistical assumptions may be needed to justify a particular loss for a scientific problem, but they are not needed for the conversion itself.
Deriving the Conversion
Divide the entire summed-loss objective by \(n\). Multiplication of an objective by a positive constant does not change which \(\beta\) minimizes it. After division, the loss is averaged, and the penalty coefficient is also divided by \(n\):
For this expression to equal the averaged-loss objective, the penalty coefficients must satisfy the following relation.
This result applies to any penalty function \(P\), not just the lasso. For example, an elastic-net penalty can be written as \(P(\beta)=\alpha\|\beta\|_1+(1-\alpha)\|\beta\|_2^2/2\), where \(\alpha\) sets the mixture of the two penalty components. If \(\alpha\) is unchanged, the whole penalty coefficient scales by \(n\); the mixture itself does not change.
Worked Example: Converting a Lasso Penalty for 80 Observations
Suppose a hypothetical lasso fit uses \(n=80\) observations and minimizes a summed squared-error loss with \(\lambda_{\mathrm{sum}}=16\). The corresponding averaged-loss penalty is
For a coefficient vector with \(\|\beta\|_1=5\) and summed loss \(120\), the summed objective is \(120+16(5)=200\). The averaged objective at the same vector is \(120/80+0.2000(5)=1.500+1.000=2.500\). Since \(200/80=2.500\), the averaged objective is exactly the summed objective divided by 80. This equality holds for every coefficient vector, not just this example, so the minimizing fit is the same.
What Happens If the Number Is Not Rescaled?
Using the same numerical \(\lambda\) with both conventions does not generally preserve the fit. The summed loss grows with the number of observations, while the averaged loss is on a per-observation scale. Consequently, a fixed penalty in a summed objective becomes relatively less influential as \(n\) increases. In an averaged objective, a fixed penalty remains on the same scale relative to the average loss, provided the distribution of per-observation losses and the predictor scaling stay comparable.
Worked Example: A Fixed Penalty Gives Different Lasso Fits
Consider a hypothetical one-coefficient regression with no intercept, \(x_i=1\) and \(y_i=3\) for all four observations. Use the lasso penalty \(|\beta|\), and define the summed squared-error objective with a factor of one-half:
For a positive minimizing coefficient, differentiating gives \(4(\beta-3)+\lambda_{\mathrm{sum}}=0\). With \(\lambda_{\mathrm{sum}}=1\), this gives \(\beta=3-1/4=2.750\). The coefficient is positive, so the assumed sign is consistent.
Under the averaged convention, the objective is \(\frac{1}{8}\sum_{i=1}^4(3-\beta)^2+\lambda_{\mathrm{avg}}|\beta|=\frac12(3-\beta)^2+\lambda_{\mathrm{avg}}|\beta|\). Its positive-coefficient derivative is \(\beta-3+\lambda_{\mathrm{avg}}=0\). If the same number, \(\lambda_{\mathrm{avg}}=1\), is used, the minimizer is \(\beta=2\), not \(2.750\). In contrast, setting \(\lambda_{\mathrm{avg}}=1/4\), as required by \(\lambda_{\mathrm{sum}}/n\), gives \(\beta=2.750\), the same fit as the summed objective.
The example is deliberately simple, but the distinction is general. For fixed data, two correctly converted objectives have the same minimizer. Two objectives using the same numerical penalty but different loss normalization generally do not. A numerical penalty value therefore cannot be interpreted independently of the convention used to define the loss.
Applying the Rule to Different Penalties and Losses
The conversion is not specific to squared-error regression. Suppose a penalized logistic-regression objective uses the sum of the observations’ negative log-likelihood contributions and an \(\ell_1\) penalty. Dividing the full objective by \(n\) again divides the penalty coefficient by \(n\). The same reasoning applies to ridge and elastic net, because the derivation requires only that the same penalty function be used in both formulations.
Worked Example: Logistic Loss on an Average Scale
Suppose a hypothetical logistic-regression fit has \(n=120\) observations. Its averaged negative log-likelihood objective uses \(\lambda_{\mathrm{avg}}=0.05000\) with an \(\ell_1\) penalty. The equivalent summed-loss parameter is
At a particular coefficient vector, suppose the summed negative log-likelihood is 84 and \(\|\beta\|_1=3\). The summed objective is \(84+6.000(3)=102\). The averaged objective is \(84/120+0.05000(3)=0.7000+0.1500=0.8500\), and \(102/120=0.8500\). Thus the objective values differ by exactly the factor 120 at this vector, as they do at every vector. This calculation demonstrates the scale conversion; it does not require fitting a new logistic model.
Some objective functions include an additional constant in their loss definition. For instance, squared-error loss is often written with a factor \(1/2\), and likelihood software may report negative log likelihood or twice the negative log likelihood. A constant multiplying the loss must also be accounted for when translating the penalty parameter. If one objective is \(c\sum_i\ell_i(\beta)+\lambda P(\beta)\), dividing by \(c\) gives \(\sum_i\ell_i(\beta)+(\lambda/c)P(\beta)\). It is therefore unsafe to compare penalties by sample size alone if the loss definitions also differ.
Likewise, “average loss” might mean an average over rows, an average over total observation weights, or an average over binomial trials. These denominators need not be the same. If the loss is weighted, write down the actual objective and its denominator before converting the penalty. The relevant scale is the multiplier applied to the loss actually being optimized, not a presumed sample size.
Checking and Reporting the Convention
When comparing penalty values, first identify the exact objective. Check whether the loss is summed or averaged, whether it includes a constant such as \(1/2\) or \(2\), and how the penalty is defined. Also check whether the intercept is penalized and whether predictors or responses have been rescaled. The sum-to-average conversion assumes these choices are otherwise the same.
A useful check is to express both objectives on a common scale. For example, divide the summed objective by \(n\), then compare its penalty coefficient and penalty function with those in the averaged objective. If they match, the objectives have the same minimizers. When reproducing a reported result, record the objective formula alongside \(\lambda\), the number of loss contributions, and any preprocessing or weighting that changes the scale.
Identify the loss term, its multiplier or denominator, the penalty function, and the penalty coefficient.
Multiply or divide the entire objective by the needed positive constant, not just the loss term.
After rescaling the objective, verify that the penalty functions, coefficient scaling, and coefficient preprocessing agree.
A common mistake is to say, “Both programs report \(\lambda=0.1\), so they applied the same regularization.” That conclusion is not justified if one program averages the loss and the other sums it. For \(n=100\), an averaged-loss parameter of \(0.1\) corresponds to a summed-loss parameter of \(10\), not \(0.1\). The correction is to compare the complete objectives after rescaling, rather than comparing the printed numbers alone.
A second, related mistake is to assume that a penalty value can be compared across data sets without accounting for sample size. Under a summed-loss convention, keeping \(\lambda_{\mathrm{sum}}\) fixed while increasing \(n\) changes the penalty relative to the loss. Under an averaged-loss convention, the parameter is expressed relative to average loss, but comparisons can still be affected by changes in predictor scaling, response scaling, weights, and loss definition.
Limitations of the Conversion
The identity \(\lambda_{\mathrm{sum}}=n\lambda_{\mathrm{avg}}\) is exact only when the objectives differ by the loss normalization described above. It does not imply that equal converted penalty values across separate studies yield the same fitted coefficients: their observations, predictors, response scales, and fitted models may differ. Nor does it make penalty values universal across software packages that standardize variables differently or use distinct loss and penalty conventions.
For a fixed data set and a fixed penalty function, the conversion preserves the entire optimization problem’s minimizers, including any nonuniqueness. It does not resolve whether the optimizer has converged, whether the modeling assumptions are appropriate, or whether a particular penalty is scientifically useful. Those questions require examining the fit and the analysis context separately.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- For \(n=50\), what averaged-loss penalty corresponds to \(\lambda_{\mathrm{sum}}=7.5\)?
- A summed-loss objective has loss sum 40 and penalty value \(P(\beta)=2\). If \(n=20\), what is its equivalent averaged objective value when converted consistently?
- Why can the same numerical \(\lambda\) produce different fits under summed and averaged loss?
- If an objective’s loss is multiplied by 2 but its penalty is unchanged, how must its penalty coefficient change to preserve the minimizer after expressing the loss without that factor?
- What information should accompany a reported penalty value so that another analyst can assess its scale?
Solutions. (1) \(\lambda_{\mathrm{avg}}=7.5/50=0.1500\). (2) The summed objective is \(40+\lambda_{\mathrm{sum}}(2)\), so its averaged equivalent is \((40+2\lambda_{\mathrm{sum}})/20=2+0.1000\lambda_{\mathrm{sum}}\); the numerical value cannot be determined without \(\lambda_{\mathrm{sum}}\). This shows why a loss and penalty value alone are insufficient. (3) The summed loss is \(n\) times the average loss, so the same penalty number has different relative weight; equivalent fits require \(\lambda_{\mathrm{sum}}=n\lambda_{\mathrm{avg}}\). (4) If the original objective is \(2L+\lambda P\), dividing by 2 gives \(L+(\lambda/2)P\), so the coefficient with unmultiplied loss is \(\lambda/2\). (5) Report the objective or loss normalization, penalty definition, sample-size or weight denominator, and relevant scaling or preprocessing choices.