Ridge
Ridge regression addresses the instability of Ordinary Least Squares when features are correlated or when the design matrix is near-singular. It does so by adding an penalty on the coefficient vector, shrinking all coefficients toward zero and improving the conditioning of the problem.
Objective Function
where controls the regularization strength: larger increases shrinkage and reduces variance at the cost of higher bias.
This formulation matches scikit-learn's Ridge, which minimizes .
Closed-Form Solution
Setting the gradient to zero yields the normal equation:
Skigen solves this system via Cholesky decomposition (Eigen::LLT), which exploits the fact that is symmetric positive definite for .
The solution is:
When fit_intercept is enabled, the data is centered before fitting: and . The intercept is then recovered as .
Computational Complexity
Forming costs , and the Cholesky solve costs , giving an overall complexity of — the same order as OLS.
When to Use
- Multicollinearity: When features are correlated and OLS produces unstable estimates with large variance.
- Ill-conditioned problems: When is near-singular, Ridge stabilizes the solution by shifting eigenvalues away from zero.
- preference: When all features are expected to contribute and full sparsity (zeroing coefficients) is not desired — use Lasso or ElasticNet for that.
Constructor
Skigen::Ridge<Scalar> model(Scalar alpha = 1, bool fit_intercept = true);
| Parameter | Default | Description |
|---|---|---|
alpha | 1 | Regularization strength () |
fit_intercept | true | Whether to center the data and compute an intercept |
Methods
| Method | Description |
|---|---|
fit(X, y) | Fit the model by solving |
predict(X) | Predict |
score(X, y) | Return the coefficient of determination |
Fitted Attributes
| Accessor | Type | Description |
|---|---|---|
coef() | RowVectorType | Estimated coefficient vector |
intercept() | Scalar | Intercept term |
Example
#include <Skigen/LinearModel>
Skigen::Ridge model(/*alpha=*/0.5);
model.fit(X, y);
auto predictions = model.predict(X_test);
For full parameter details and method signatures, see the auto-generated Ridge API Reference.