spe.smoothers.BSplineRegressor#

class spe.smoothers.BSplineRegressor(n_knots=5, degree=3, knots='uniform', extrapolation='linear', include_bias=True, order='C', sparse_output=False)#

BSpline linear regression model.

Generate feature matrix of B-splines and fit a linear regression to that expanded feature set.

Parameters:
n_knotsint, optional

Number of knots of the splines if knots equals one of {‘uniform’, ‘quantile’}. Must be larger or equal 2. Ignored if knots is array-like. Default is 5.

degreeint, optional

The polynomial degree of the spline basis. Must be a non-negative integer. Default is 3.

knots{‘uniform’, ‘quantile’} or array-like of shape (n_knots, n_features), optional

Set knot positions such that first knot <= features <= last knot. Default is ‘uniform’.

  • If ‘uniform’, n_knots number of knots are distributed uniformly from min to max values of the features.

  • If ‘quantile’, they are distributed uniformly along the quantiles of the features.

  • If an array-like is given, it directly specifies the sorted knot positions including the boundary knots. Note that, internally, degree number of knots are added before the first knot, the same after the last knot.

extrapolation{‘error’, ‘constant’, ‘linear’, ‘continue’, ‘periodic’}, optional

If ‘error’, values outside the min and max values of the training features raises a ValueError. If ‘constant’, the value of the splines at minimum and maximum value of the features is used as constant extrapolation. If ‘linear’, a linear extrapolation is used. If ‘continue’, the splines are extrapolated as is, i.e. option extrapolate=True in scipy.interpolate.BSpline. If ‘periodic’, periodic splines with a periodicity equal to the distance between the first and last knot are used. Periodic splines enforce equal function values and derivatives at the first and last knot. For example, this makes it possible to avoid introducing an arbitrary jump between Dec 31st and Jan 1st in spline features derived from a naturally periodic “day-of-year” input feature. In this case it is recommended to manually set the knot values to control the period. Default is ‘constant’.

include_biasbool, optional

If False, then the last spline element inside the data range of a feature is dropped. As B-splines sum to one over the spline basis functions for each data point, they implicitly include a bias term, i.e. a column of ones. It acts as an intercept term in a linear models. Default is True.

order{‘C’, ‘F’}, optional

Order of output array in the dense case. ‘F’ order is faster to compute, but may slow down subsequent estimators. Default is ‘C’.

sparse_outputbool, optional

Will return sparse CSR matrix if set True else will return an array. This option is only available with scipy>=1.8. Default is False.

Methods

__init__([n_knots, degree, knots, ...])

fit(X, y)

get_group_X(X[, X_pred])

get_linear_smoother(X, tr_idx, ts_idx[, ...])

Get fitted adaptive linear smoother matrix \(S(W)\).

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X)

Compute \(S(W)y_{refit}\) as predictions.

set_params(**params)

Set the parameters of this estimator.

__init__(n_knots=5, degree=3, knots='uniform', extrapolation='linear', include_bias=True, order='C', sparse_output=False)#
fit(X, y)#
get_group_X(X, X_pred=None)#
get_linear_smoother(X, tr_idx, ts_idx, ret_full_P=False)#

Get fitted adaptive linear smoother matrix \(S(W)\).

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

predict(X)#

Compute \(S(W)y_{refit}\) as predictions.

Computes predictions as adaptive linear smoothing where \(S(W)\) is the output of instance’s AdaptiveLinearSmoother().

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.