CubicRegressionSpline#

class superglm.CubicRegressionSpline(
n_knots: int = 10,
knot_strategy: Literal['uniform', 'quantile', 'quantile_rows', 'quantile_tempered'] = 'uniform',
penalty: Literal['ssp', 'none'] | None = 'ssp',
select: bool = False,
knots: ArrayLike | None = None,
discrete: bool | None = None,
n_bins: int | None = None,
extrapolation: Literal['clip', 'extend', 'error'] = 'clip',
boundary: tuple[float, float] | None = None,
knot_alpha: float = 0.2,
constraint=None,
m: int | tuple[int, ...] = 2,
lambda_policy: LambdaPolicy | dict[str, LambdaPolicy] | None = None,
polynomial_ranges: Sequence[PolynomialRange] | None = None,
)#

Bases: _IntegratedPenaltySpline

CR spline: integrated f’’ squared penalty + natural boundary constraints.

Compatible with the standard cubic regression spline construction used in GAM packages. Always cubic (degree=3). Natural boundary constraints (f’’=0 at boundaries) are mandatory. The basis has linear tails, but default prediction still clips at the training boundary unless extrapolation="extend" is used.

The penalty matrix is the wiggliness penalty: omega_ij = int B_i’’(x) B_j’’(x) dx, computed via Gauss-Legendre quadrature over each knot interval.

Multi-order penalties (m tuple) are a SuperGLM extension, not strict mgcv bs="cr" parity.

Parameters:
constraintConstraintSpec, ConstraintRules or None

Public shape-constraint token, or fit-time rules joined with & into a ConstraintRules. Use Constraint.fit.increasing, Constraint.fit.decreasing, Constraint.fit.convex, Constraint.fit.concave, or any of the corresponding Constraint.postfit.* kinds. Fit-time constraints apply on the spline term’s linear-predictor contribution and use the constrained QP solver path. An increasing or decreasing rule holds the adjacent B-spline coefficient differences of the natural cubic to one sign. That is sufficient for a monotone curve but not necessary, like the linear conditions of Wood (1994) behind mgcv’s mono.con, so the fit is the best curve in a smaller set than all monotone curves; more knots narrow the gap. Convex and concave rules are exact. With fit_reml(), fixed lambdas work directly; automatic lambda estimation uses the QP passthrough heuristic (unconstrained REML followed by constrained refit), not exact joint constrained REML.

polynomial_rangessequence of PolynomialRange or None

Ranges of the axis on which the curve is pinned to a polynomial of the range’s degree; the rest stays the penalised smooth, and the penalty skips the pinned intervals. A range reaching an end replaces that end’s natural condition.