s#

pygam.terms.s(feature, n_splines=20, spline_order=3, lam=0.6, penalties='auto', constraints=None, dtype='numerical', basis='ps', by=None, edge_knots=None, verbose=False)[source]#

Creates an instance of a SplineTerm.

Parameters:
featureint

Index of the feature to use for the feature function.

n_splinesint, default=20

Number of splines to use for the feature function.

Must be non-negative.

spline_orderint, default=3

Order of spline to use for the feature function.

Must be non-negative.

lamfloat or iterable of floats, default=0.6

Strength of smoothing penalty. Must be a positive float.

Larger values enforce stronger smoothing.

If single value is passed, it will be repeated for every penalty.

If iterable is passed, the length of lam must be equal to the length of penalties

penalties{‘auto’, ‘derivative’, ‘l2’, None} or callable or iterable, default=’auto’

Type of smoothing penalty to apply to the term.

If an iterable is used, multiple penalties are applied to the term. The length of the iterable must match the length of lam.

If 'auto', then 2nd derivative smoothing for 'numerical' dtypes, and L2/ridge smoothing for 'categorical' dtypes.

Custom penalties can be passed as callables.

constraints{None, ‘convex’, ‘concave’, ‘monotonic_inc’, ‘monotonic_dec’}

or callable or iterable, defualt=None

Type of constraint to apply to the term.

If an iterable is used, multiple penalties are applied to the term.

dtype{‘numerical’, ‘categorical’}, default=’numerical’

String describing the data-type of the feature.

basis{‘ps’, ‘cp’}, default=’ps’

Type of basis function to use in the term.

ps :

p-spline basis

cp :

Cyclic p-spline basis, useful for building periodic functions.

By default, the maximum and minimum of the feature values are used to determine the function’s period.

To specify a custom period use argument edge_knots

edge_knotsoptional, array-like of floats of length 2, default=None

These values specify minimum and maximum domain of the spline function.

In the case that basis="cp", edge_knots determines the period of the cyclic function.

When edge_knots=None these values are inferred from the data.

byint, optional, default=None

Feature to use as a by-variable in the term.

For example, if feature = 2 by = 0, then the term will produce:

>>> x0 * f(x2)
Attributes:
n_coefsint

Number of coefficients contributed by the term to the model

istensorbool

whether the term is a tensor product of sub-terms

isinterceptbool

whether the term is an intercept

hasconstraintbool

whether the term has any constraints

infodict

contains dict with the sufficient information to duplicate the term

See also

SplineTerm

for developer details