Skip to content

Ridge

from SymbolicDSGE.regression.ridge import RidgeResult, ridge, ridge_gs
ridge(
    x: ndarray,
    y: ndarray,
    alpha: float,
    variables: list[str] | None = None,
    intercept: bool = True,
) -> RidgeResult

Run ridge regression with an L2 penalty.

Inputs:

Name Description
x Design matrix. Shape (n, k).
y Response vector. Shape (n,).
alpha Non-negative L2 penalty weight.
variables Optional names for the columns of x. Defaults to x0, x1, ...
intercept If True, prepend an unpenalized intercept column to the returned design matrix.

Returns:

Type Description
RidgeResult Regression result with ridge penalty diagnostics.

 

ridge_gs(
    x: ndarray,
    y: ndarray,
    start: float,
    stop: float,
    num: int,
    criterion: Literal["aic", "bic", "loss"] = "aic",
    variables: list[str] | None = None,
    intercept: bool = True,
) -> RidgeResult

Run ridge regression over a logarithmic alpha grid and return the best result under the selected criterion.

Inputs:

Name Description
start Positive lower endpoint for the alpha grid.
stop Positive upper endpoint for the alpha grid.
num Number of grid points.
criterion Grid-search objective: AIC, BIC, or residual loss.
x, y, variables, intercept Same contract as ridge(...).

 

@dataclass(frozen=True)
class RidgeResult(RegressionResult)

Additional Fields and Properties:

Name Type Description
alpha float64 Selected L2 penalty weight.
effective_dof float64 Effective degrees of freedom used by grid-search criteria.
intercept bool Whether the returned design includes an intercept column.
objective RidgeObjective | None Grid-search criterion used to select alpha, if applicable.
objective_value float64 | None Realized grid-search criterion value, if applicable.
l2_penalty float64 Realized ridge penalty excluding the intercept term.
Penalty Convention

When intercept=True, the intercept is not included in l2_penalty and is not regularized by the solver.