pysindy.feature_library.PolynomialLibrary
- class pysindy.feature_library.PolynomialLibrary(degree=2, include_interaction=True, interaction_only=False, include_bias=True, order='C')[source]
Generate polynomial and interaction features.
This is the same as
sklearn.preprocessing.PolynomialFeatures, but also adds the option to omit interaction features from the library.- Parameters:
degree (integer, optional (default 2)) – The degree of the polynomial features.
include_interaction (boolean, optional (default True)) – Determines whether interaction features are produced. If false, features are all of the form
x[i] ** k.interaction_only (boolean, optional (default False)) – If true, only interaction features are produced: features that are products of at most
degreedistinct input features (so notx[1] ** 2,x[0] * x[2] ** 3, etc.).include_bias (boolean, optional (default True)) – If True (default), then include a bias column, the feature in which all polynomial powers are zero (i.e. a column of ones - acts as an intercept term in a linear model).
order (str in {'C', 'F'}, optional (default 'C')) – Order of output array in the dense case. ‘F’ order is faster to compute, but may slow down subsequent estimators.
- Attributes:
powers_ (array, shape (n_output_features, n_input_features)) – powers_[i, j] is the exponent of the jth input in the ith output.
n_features_in_ (int) – The total number of input features.
n_output_features_ (int) – The total number of output features. This number is computed by iterating over all appropriately sized combinations of input features.
Methods
Compute number of output features.
Return feature names for output features.
Configure whether metadata should be requested to be passed to the
fitmethod.Configure whether metadata should be requested to be passed to the
transformmethod.Transform data to polynomial features.
Attributes
The exponents of the polynomial as an array of shape (n_features_out, n_features_in), where each item is the exponent of the jth input variable in the ith polynomial term.
n_features_in_n_output_features_- fit(x_full: list[AxesArray], y=None)[source]
Compute number of output features.
- Parameters:
x (array-like, shape (n_samples, n_features)) – The data.
- Returns:
self
- Return type:
instance
- get_feature_names(input_features=None)[source]
Return feature names for output features.
- Parameters:
input_features (list of string, length n_features, optional) – String names for input features if available. By default, “x0”, “x1”, … “xn_features” is used.
- Returns:
output_feature_names
- Return type:
list of string, length n_output_features
- property powers_: ndarray[tuple[Any, ...], dtype[int64]]
The exponents of the polynomial as an array of shape (n_features_out, n_features_in), where each item is the exponent of the jth input variable in the ith polynomial term.
- set_fit_request(*, x_full: bool | None | str = '$UNCHANGED$') PolynomialLibrary
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
x_full (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x_fullparameter infit.- Returns:
self – The updated object.
- Return type:
object
- set_transform_request(*, x_full: bool | None | str = '$UNCHANGED$') PolynomialLibrary
Configure whether metadata should be requested to be passed to the
transformmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
x_full (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
x_fullparameter intransform.- Returns:
self – The updated object.
- Return type:
object
- transform(x_full)[source]
Transform data to polynomial features.
- Parameters:
x_full ({array-like, sparse matrix} of shape (n_samples, n_features)) – The data to transform, row by row.
- Returns:
xp – shape (n_samples, n_output_features) The matrix of features, where n_output_features is the number of polynomial features generated from the combination of inputs.
- Return type:
np.ndarray or CSR/CSC sparse matrix,