Class: SplineTransformer
Generate univariate B-spline bases for features.
Generate a new feature matrix consisting of n_splines=n_knots + degree \- 1
(n_knots \- 1
for extrapolation="periodic"
) spline basis functions (B-splines) of polynomial order=degree
for each feature.
In order to learn more about the SplineTransformer class go to: Time-related feature engineering
Read more in the User Guide.
Constructors
new SplineTransformer()
new SplineTransformer(
opts
?):SplineTransformer
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.degree ? | number | The polynomial degree of the spline basis. Must be a non-negative integer. |
opts.extrapolation ? | "linear" | "constant" | "error" | "continue" | "periodic" | 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. |
opts.include_bias ? | boolean | 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. |
opts.knots ? | ArrayLike [] | "uniform" | "quantile" | Set knot positions such that first knot <= features <= last knot. |
opts.n_knots ? | number | 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. |
opts.order ? | "C" | "F" | Order of output array in the dense case. 'F' order is faster to compute, but may slow down subsequent estimators. |
opts.sparse_output ? | boolean | Will return sparse CSR matrix if set true else will return an array. This option is only available with scipy>=1.8 . |
Returns SplineTransformer
Defined in generated/preprocessing/SplineTransformer.ts:27
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/preprocessing/SplineTransformer.ts:25 |
_isInitialized | boolean | false | generated/preprocessing/SplineTransformer.ts:24 |
_py | PythonBridge | undefined | generated/preprocessing/SplineTransformer.ts:23 |
id | string | undefined | generated/preprocessing/SplineTransformer.ts:20 |
opts | any | undefined | generated/preprocessing/SplineTransformer.ts:21 |
Accessors
bsplines_
Get Signature
get bsplines_():
Promise
<any
[]>
List of BSplines objects, one for each feature.
Returns Promise
<any
[]>
Defined in generated/preprocessing/SplineTransformer.ts:428
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/preprocessing/SplineTransformer.ts:482
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
The total number of input features.
Returns Promise
<number
>
Defined in generated/preprocessing/SplineTransformer.ts:455
n_features_out_
Get Signature
get n_features_out_():
Promise
<number
>
The total number of output features, which is computed as n_features \* n_splines
, where n_splines
is the number of bases elements of the B-splines, n_knots + degree \- 1
for non-periodic splines and n_knots \- 1
for periodic ones. If include_bias=False
, then it is only n_features \* (n_splines \- 1)
.
Returns Promise
<number
>
Defined in generated/preprocessing/SplineTransformer.ts:509
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/preprocessing/SplineTransformer.ts:81
Methods
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/preprocessing/SplineTransformer.ts:135
fit()
fit(
opts
):Promise
<any
>
Compute knot positions of splines.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Individual weights for each sample. Used to calculate quantiles if knots="quantile" . For knots="uniform" , zero weighted observations are ignored for finding the min and max of X . |
opts.X ? | ArrayLike [] | The data. |
opts.y ? | any | Ignored. |
Returns Promise
<any
>
Defined in generated/preprocessing/SplineTransformer.ts:152
fit_transform()
fit_transform(
opts
):Promise
<any
[]>
Fit to data, then transform it.
Fits transformer to X
and y
with optional parameters fit_params
and returns a transformed version of X
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Additional fit parameters. |
opts.X ? | ArrayLike [] | Input samples. |
opts.y ? | ArrayLike | Target values (undefined for unsupervised transformations). |
Returns Promise
<any
[]>
Defined in generated/preprocessing/SplineTransformer.ts:198
get_feature_names_out()
get_feature_names_out(
opts
):Promise
<any
>
Get output feature names for transformation.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.input_features ? | any | Input features. |
Returns Promise
<any
>
Defined in generated/preprocessing/SplineTransformer.ts:244
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/preprocessing/SplineTransformer.ts:282
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/preprocessing/SplineTransformer.ts:94
set_fit_request()
set_fit_request(
opts
):Promise
<any
>
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/preprocessing/SplineTransformer.ts:322
set_output()
set_output(
opts
):Promise
<any
>
Set output container.
See Introducing the set_output API for an example on how to use the API.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.transform ? | "default" | "pandas" | "polars" | Configure output of transform and fit_transform . |
Returns Promise
<any
>
Defined in generated/preprocessing/SplineTransformer.ts:360
transform()
transform(
opts
):Promise
<ArrayLike
>
Transform each feature data to B-splines.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The data to transform. |
Returns Promise
<ArrayLike
>