cleverly.bases.BSpline#

class cleverly.bases.BSpline(columns: Sequence[str], n_interior_knots: int = 3, degree: int = 3, domains: Mapping[str, tuple[float, float]] | tuple[tuple[str, tuple[float, float]], ...] = (), intercept: bool = True)[source]#

B-splines of each modifier with equally spaced knots on its declared domain.

The knots divide the declared domain into n_interior_knots + 1 equal spans; they are never sample quantiles. The B-splines of one modifier sum to one, so under an intercept the first of them is dropped to keep the design of full rank.

Parameters:
columnssequence of str

The continuous modifiers.

n_interior_knotsint

The number of interior knots per modifier.

degreeint

The polynomial degree, 3 for cubic splines.

domainsmapping of str to (float, float), optional

Domains carried by the basis itself, which take precedence over the schema’s.

interceptbool

Whether to prepend the intercept column.

Methods#

BSpline.domain_of(column: str) → tuple[float, float] | None[source]#

The domain this basis carries for column, or None.

Parameters:
columnstr

A modifier column.

Returns:
tuple of float or None

(low, high), or None.

BSpline.truncate(k: int) → BSpline[source]#

The same splines with k equally spaced interior knots.

Parameters:
kint

A knot count between zero and max_size.

Returns:
BSpline

The basis with k interior knots.

Attributes#

BSpline.degree: int = 3#
BSpline.domains: Mapping[str, tuple[float, float]] | tuple[tuple[str, tuple[float, float]], ...] = ()#
BSpline.intercept: bool = True#
BSpline.max_size#

The declared number of interior knots.

BSpline.n_interior_knots: int = 3#
BSpline.columns: Sequence[str]#

The modifier columns the basis reads: a field or a property of each subclass.