stable_cart.shrinkage_coefficients

stable_cart.shrinkage_coefficients(X, y, mu, beta=None, sigma=None, signal='pooled')[source]

Coefficients of the estimator that achieves the frontier point at mu.

Shrinks the least-squares solution along each singular direction by \(s_j = d_j^2\theta_j^2/(d_j^2\theta_j^2 + \mu\sigma^2)\), which is the exact solution of “minimize squared bias subject to a variance budget” — see linear_frontier().

Parameters

X

Full-column-rank design matrix of shape (n_samples, n_features).

y

Targets of shape (n_samples,).

mu

Price of variance. mu=0 returns least squares; mu=1 minimizes risk; larger values buy stability at more than it is worth in accuracy.

beta

True coefficients, if known. Estimated from the data when omitted.

sigma

True noise level, if known. Estimated as \(\sqrt{\mathrm{RSS}/(n-p)}\) when omitted.

signal

How to supply the unknown signal strength when beta is not given. 'pooled' estimates one value for all directions, which makes this ridge regression and is safer when signal is spread across directions. 'per_direction' estimates each direction separately; its estimation cost loses for diffuse signal but it can win decisively when signal is concentrated in a few singular directions. See linear_frontier() for the measured boundaries.

Returns

NDArray[np.floating]

Coefficients of shape (n_features,).

Raises

ValueError

If mu or sigma is negative or nonfinite, any array input is nonfinite, or the design is not full column rank.

Examples

>>> import numpy as np
>>> from stable_cart import shrinkage_coefficients
>>> rng = np.random.default_rng(0)
>>> X = rng.normal(size=(200, 4)); y = X @ np.arange(4.0) + rng.normal(size=200)
>>> ols = shrinkage_coefficients(X, y, mu=0.0)
>>> shrunk = shrinkage_coefficients(X, y, mu=5.0)
>>> bool(np.linalg.norm(shrunk) < np.linalg.norm(ols))
True
Parameters:
  • X (NDArray[floating])

  • y (NDArray[floating])

  • mu (float)

  • beta (NDArray[floating] | None)

  • sigma (float | None)

  • signal (str)

Return type:

NDArray[floating]