Tutorials › Regression Analysis (Undergraduate) › Choosing a Tuning Loss and Response Scale

Ridge and Lasso Regression · Tutorial 681 of 991

Choosing a Tuning Loss and Response Scale

Learn to choose a cross-validation loss that matches the prediction goal and to distinguish changes in scoring scale from changes in the fitted penalized model.

Advanced 9 min read

What You'll Learn

  • Define squared-error and absolute-error cross-validation criteria
  • Explain why the two criteria can select different penalties
  • Track how changing outcome units rescales validation scores
  • Derive how response scaling affects ridge and lasso penalty values
  • Distinguish unit conversions from nonlinear response transformations
  • Choose and report a validation loss on a clearly stated response scale

Why the Tuning Loss and Response Scale Matter

Cross-validation compares predictions with held-out outcomes. But “prediction error” is not a single quantity: squaring errors penalizes large misses more strongly than taking absolute values. The choice can therefore change which ridge or lasso penalty is preferred, even when every candidate model is evaluated on the same folds.

The scale of the response matters too. Measuring a response in grams rather than kilograms changes the numerical size of every error. Taking a logarithm changes more than the units: it changes the distances between outcomes and can change the relative importance assigned to different prediction errors. A tuning decision is interpretable only when both the scoring rule and the response scale are stated.

Definition: For validation outcomes \(y_i\) and predictions \(\hat{y}_i\), the squared error is \((y_i-\hat{y}_i)^2\), and the absolute error is \(|y_i-\hat{y}_i|\). Their average values are the mean squared error (MSE) and mean absolute error (MAE). Cross-validation estimates either quantity using predictions for observations held out from model fitting.

Two Ways to Score the Same Candidate Models

For a fixed set of cross-validation folds and a candidate penalty \(\lambda\), fit the penalized regression model using each fold’s training data and predict the corresponding held-out observations. Pool the held-out predictions so each observation contributes once. If there are \(N\) held-out predictions in total, the pooled cross-validation scores are

$$ \operatorname{CV}_{\mathrm{MSE}}(\lambda) = \frac{1}{N}\sum_{i=1}^{N}(y_i-\hat{y}_{i,\lambda})^2, \qquad \operatorname{CV}_{\mathrm{MAE}}(\lambda) = \frac{1}{N}\sum_{i=1}^{N}|y_i-\hat{y}_{i,\lambda}|. $$

The selected penalty minimizes the chosen score over the candidate values of \(\lambda\). MSE gives a disproportionate contribution to large errors because the error is squared. MAE treats error increases linearly: doubling an absolute error doubles its contribution. Neither criterion is universally best. MSE is appropriate when large misses should count especially heavily and squared error reflects the prediction objective. MAE can be more aligned with a goal of limiting typical absolute deviations.

In this setting, ridge and lasso candidates are fitted by minimizing a penalized squared-error objective on each training fold. Choosing MAE for validation does not turn the fitted models into absolute-error regression models. It changes how their held-out predictions are compared, not the criterion used to estimate their coefficients.

Key distinction: The fitting loss is the criterion used to estimate a candidate model’s coefficients. The validation loss is the criterion used to score its held-out predictions and choose among candidate penalties. They can be different, but each must be identified clearly.

Worked Example: Squared and Absolute Error Select Different Penalties

Suppose the held-out outcomes, measured in minutes, are 10, 20, 30, and 40. Two candidate penalties produce predictions as follows:

OutcomeObservedPrediction, penalty APrediction, penalty B
1101012
2202022
3303032
4404642

For penalty A, the residuals (observed minus predicted) are \(0,0,0,-6\). Thus

$$ \operatorname{MSE}(A)=\frac{0^2+0^2+0^2+(-6)^2}{4} =\frac{36}{4}=9\ \text{minutes}^2, $$

and

$$ \operatorname{MAE}(A)=\frac{|0|+|0|+|0|+|-6|}{4} =\frac{6}{4}=1.5\ \text{minutes}. $$

For penalty B, the residuals are \(-2,-2,-2,-2\), so

$$ \operatorname{MSE}(B)=\frac{4+4+4+4}{4}=4\ \text{minutes}^2, \qquad \operatorname{MAE}(B)=\frac{2+2+2+2}{4}=2\ \text{minutes}. $$

MSE is smaller for B, while MAE is smaller for A. If squared-error cross-validation is the stated tuning rule, B is selected; if absolute-error cross-validation is the rule, A is selected. The difference arises because A has three exact predictions and one relatively large miss, while B has four moderate misses. The example does not establish that either penalty is best for every purpose; it shows that the scoring rule answers which candidate is best according to a particular measure of predictive error.

Response Units: Scores Change, Rankings Usually Do Not

Suppose outcomes and predictions are converted from one unit to another by multiplying by a fixed positive constant \(c\). Each residual is then multiplied by \(c\). Consequently, MAE is multiplied by \(c\), and MSE is multiplied by \(c^2\). Since these are positive constants, the ordering of candidate models by a given loss does not change if all predictions are converted consistently and the fitted predictions themselves remain equivalent.

$$ |c y_i-c\hat{y}_i|=c|y_i-\hat{y}_i|, \qquad (c y_i-c\hat{y}_i)^2=c^2(y_i-\hat{y}_i)^2 \quad (c>0). $$

For example, reporting time in seconds rather than minutes multiplies MAE scores by 60 and MSE scores by \(60^2=3600\). The numerical value and units of the score change, but a common positive multiplier does not change which candidate has the smallest score. This invariance concerns the ranking under a fixed criterion; it does not mean the numerical penalty value \(\lambda\) is automatically unchanged when the response units used to fit the models change.

Worked Example: Converting the Validation Scores to Smaller Units

In the preceding example, convert the outcomes and predictions from minutes to seconds by multiplying each by 60. Penalty A’s MAE becomes

$$ 60(1.5)=90\ \text{seconds}, $$

and its MSE becomes

$$ 60^2(9)=3600(9)=32{,}400\ \text{seconds}^2. $$

Penalty B’s scores become \(60(2)=120\) seconds for MAE and \(3600(4)=14{,}400\) seconds squared for MSE. Under MSE, B still has the smaller score, \(14{,}400<32{,}400\). Under MAE, A still has the smaller score, \(90<120\). The score values changed because the units changed, but each criterion’s ranking did not.

This conclusion requires a consistent conversion: both observed outcomes and predictions must be expressed in seconds, and each candidate’s predictions must represent the same fitted predictions after conversion. Comparing a score in seconds with one in minutes would not be a meaningful comparison.

Why Response Scaling Can Change the Penalty Value

A ridge or lasso model is fitted by balancing a squared-error term against a penalty on the coefficients. For a training set of size \(n\), write the objective as

$$ Q_{\lambda}(\beta_0,\boldsymbol{\beta}) = \frac{1}{2n}\sum_{i=1}^{n} \left(y_i-\beta_0-\sum_{j=1}^{p}\beta_j x_{ij}\right)^2 +\lambda P(\boldsymbol{\beta}), $$

where the intercept \(\beta_0\) is not penalized, \(\boldsymbol{\beta}\) is the vector of predictor coefficients, and \(P\) is the penalty. For ridge, take \(P(\boldsymbol{\beta})=\frac{1}{2}\sum_{j=1}^{p}\beta_j^2\); for lasso, take \(P(\boldsymbol{\beta})=\sum_{j=1}^{p}|\beta_j|\). The factor \(1/(2n)\) specifies the objective convention used here.

If the response is multiplied by \(c>0\), equivalent predictions and coefficients are multiplied by \(c\). But the squared-error term scales by \(c^2\), while the ridge and lasso penalties scale differently. This gives different penalty adjustments for equivalent fits.

1
Scale the outcome and coefficients.
Let \(y_i^*=c y_i\), \(\beta_0^*=c\beta_0\), and \(\beta_j^*=c\beta_j\). Then each fitted value and residual is multiplied by \(c\), so the squared-error term is multiplied by \(c^2\).
2
Compare ridge penalties.
The ridge penalty for the scaled coefficients is \(\frac{1}{2}\sum_j(c\beta_j)^2=c^2\frac{1}{2}\sum_j\beta_j^2\). Both terms scale by \(c^2\), so the equivalent ridge objective uses the same \(\lambda\).
3
Compare lasso penalties.
The lasso penalty becomes \(\sum_j|c\beta_j|=c\sum_j|\beta_j|\). To scale the full objective by \(c^2\), its penalty coefficient must be \(\lambda^*=c\lambda\).

The calculation can be expressed directly. For ridge, using \(\lambda^*=\lambda\) makes the scaled objective equal to \(c^2 Q_\lambda\) at the corresponding scaled coefficients. For lasso, using \(\lambda^*=c\lambda\) does the same. Multiplying an objective by a positive constant does not change its minimizer, which justifies these equivalences. With a conversion factor below one, the same formulas apply with that positive value of \(c\).

This is a statement about equivalent fits under the objective just defined, not a universal software rule. Software may use a different normalization, and candidate penalty grids may be generated differently. Comparisons of numerical \(\lambda\) values therefore require the same objective convention and response scale. Also, this scaling result concerns a constant change of units. It does not apply unchanged to nonlinear transformations such as taking logarithms.

Worked Example: Matching Fits After Changing Response Units

Suppose a lasso model is fitted to an outcome measured in kilograms with \(\lambda=0.04\), using the objective above. The outcome is then represented in grams, so \(c=1000\). To obtain an equivalent lasso fit, use

$$ \lambda^*=c\lambda=1000(0.04)=40. $$

The coefficients and fitted values are multiplied by 1000, and the squared-error term is multiplied by \(1000^2\). The lasso penalty is multiplied by 1000; using \(\lambda^*=40\) makes that penalty contribution scale by \(1000(40)=40{,}000\), which is \(1000^2(0.04)\). Thus both contributions scale by the same factor, \(1{,}000{,}000\), and the minimizer corresponds to the original fit after conversion to grams.

For ridge, the equivalent numerical penalty remains \(0.04\) under this objective, because the squared coefficient penalty also scales by \(1000^2\). In either case, these are statements about matching fitted models after response conversion. They do not assert that an unchanged numerical penalty grid in every implementation will produce identical models.

Nonlinear Transformations Change the Prediction Question

A nonlinear response transformation does not simply multiply every error by one common constant. For instance, when outcomes are positive, comparing absolute errors in \(y\) is different from comparing absolute errors in \(\log(y)\). Log-scale errors compare multiplicative differences: the error between an observed value \(y\) and a prediction \(\hat{y}\) depends on \(|\log(y/\hat{y})|\). A prediction that is a fixed proportion above an outcome can therefore have the same absolute log error across different outcome magnitudes, even though its absolute error in the original units differs.

The scale used for validation should match the practical prediction goal. If the goal is to predict an outcome in its original units, evaluate predictions on that scale. If the goal concerns relative or multiplicative accuracy, a log-scale criterion may be suitable. When fitting on a transformed response, also state how predictions are produced on the scale used for scoring. A model prediction on the log scale is not automatically an estimate of the conditional mean on the original scale; exponentiating it does not in general recover that mean.

Worked Example: Absolute Error and Log Error Rank Models Differently

Consider two positive validation outcomes, 10 and 100 units. Candidate A predicts 14 and 80; candidate B predicts 16 and 90. On the original scale, their absolute errors are \(4,20\) for A and \(6,10\) for B. Their MAEs are

$$ \operatorname{MAE}(A)=\frac{4+20}{2}=12, \qquad \operatorname{MAE}(B)=\frac{6+10}{2}=8. $$

Thus original-scale MAE favors B. Now score absolute errors on the natural-log scale. Candidate A has

$$ |\log(10/14)|=|\log(1/1.4)|\approx 0.3365, \qquad |\log(100/80)|=|\log(1.25)|\approx 0.2231. $$

Its mean absolute log error is approximately \((0.3365+0.2231)/2=0.2798\). Candidate B has

$$ |\log(10/16)|=|\log(1/1.6)|\approx 0.4700, \qquad |\log(100/90)|=|\log(10/9)|\approx 0.1054. $$

Its mean absolute log error is approximately \((0.4700+0.1054)/2=0.2877\). The log-scale criterion favors A, since \(0.2798<0.2877\). There is no contradiction: the two criteria measure different notions of prediction error. These calculations compare the stated predictions on two scales; they do not claim that fitting a model to logged outcomes and then exponentiating its predictions necessarily produces these particular original-scale predictions.

Common Pitfall and Practical Reporting

A common mistake is to treat a smaller numerical cross-validation score as automatically better, without checking the loss definition and units. For example, \(0.8\) squared units cannot be judged directly against \(1.1\) units of absolute error: they are different measures with different units. Nor does choosing MAE mean that the coefficient-fitting procedure minimized absolute error.

Before reporting a tuning result, make explicit:

  • Whether the validation criterion is MSE, MAE, or another stated loss.
  • The response scale and units on which observed values and predictions were compared.
  • Whether the candidate models were fitted using the same training procedure and fold assignments.
  • The selected penalty and the criterion value, with units where applicable (MSE has squared response units; MAE has response units).

When transformations or standardization are estimated from data, they must be learned using only the training portion of each fold and then applied to its held-out portion. Otherwise information from validation outcomes can affect the fitting or preprocessing and undermine the intended held-out comparison. Finally, cross-validation selects among the candidates and scoring choices actually considered; the result is not proof that the selected model will be best in every future setting.

Key takeaway: Choose the validation loss and response scale to match the prediction goal. A constant unit conversion rescales scores without changing their within-criterion ranking when fits are converted consistently; a nonlinear transformation can change the ranking. Under the stated squared-error fitting objective, response rescaling also changes the equivalent lasso penalty differently from the ridge penalty.

Check Your Understanding

Answer each question by referring to both the scoring rule and the response scale.

  1. Why can two penalties be ranked differently by cross-validation MSE and MAE even when they use the same validation observations?
  2. If outcomes and predictions are converted from meters to centimeters, by what factor do MAE and MSE change? Does either within-criterion ranking change?
  3. Under the stated objective, if the response is multiplied by a positive constant \(c\), how must the equivalent ridge and lasso penalty values change?
  4. Does choosing MAE for validation mean that the ridge or lasso coefficients were fitted by minimizing absolute error? Explain.
  5. Why can selecting a penalty using absolute error on the original outcome differ from selecting it using absolute error on the log outcome?