Skip to content

Implement ridge with an unpenalised intercept

Question

Implement Python ridge regression for a finite two-dimensional design matrix X and one-dimensional target y, with positive penalty and an unpenalised intercept. Explain why you avoid an explicit matrix inverse.

Short answer

Centre X and y, solve the penalised normal system, then restore the intercept. Positive penalty ensures invertibility of the centred system, although QR/SVD formulations can offer better numerical conditioning.

Original question and answer written by SelfMadeQuant.com.

See the hint and the full worked solution in the question bank (free account).

Open the worked solution

Lessons behind this question

Start with a free lesson: Basic Statistics and Regression is part of a free topic. Create a free account, no card needed, to read it in full with worked solutions.

Read it free