skbel.preprocessing

This package contains classes for preprocessing data.

skbel.preprocessing.composite

class skbel.preprocessing.composite.CompositePCA(n_components: list, scale: bool = False)[source]

Bases: TransformerMixin, BaseEstimator

__init__(n_components: list, scale: bool = False)[source]

Initiate the class by specifying a list of number of components to keep for each different datasets.

Parameters:
  • n_components – list of number of components to keep for each dataset

  • scale – whether to scale the data before applying PCA

_sklearn_auto_wrap_output_keys = {'transform'}
fit(Xc: list, yc=None, **fit_params)[source]

Fit all PCA objects for the different datasets with their specified n_components.

Parameters:
  • Xc – list of datasets

  • yc – Only here to satisfy the scikit-learn API

Returns:

self

fit_transform(Xc: list, yc=None, **fit_params)[source]

Fit and transform all datasets.

Parameters:
  • Xc – list of datasets

  • yc – Only here to satisfy the scikit-learn API

Returns:

concatenated output

inverse_transform(Xr: array, yc=None, **fit_params) list[source]

Inverse transform the data back to the original space.

Parameters:
  • Xr – transformed data

  • yc – Only here to satisfy the scikit-learn API

Returns:

list of transformed datasets

set_fit_request(*, Xc: bool | None | str = '$UNCHANGED$', yc: bool | None | str = '$UNCHANGED$') CompositePCA

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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

Xcstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for Xc parameter in fit.

ycstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for yc parameter in fit.

Returns

selfobject

The updated object.

set_inverse_transform_request(*, Xr: bool | None | str = '$UNCHANGED$', yc: bool | None | str = '$UNCHANGED$') CompositePCA

Configure whether metadata should be requested to be passed to the inverse_transform method.

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 (see sklearn.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 to inverse_transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to inverse_transform.

  • 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

Xrstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for Xr parameter in inverse_transform.

ycstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for yc parameter in inverse_transform.

Returns

selfobject

The updated object.

set_transform_request(*, Xc: bool | None | str = '$UNCHANGED$', yc: bool | None | str = '$UNCHANGED$') CompositePCA

Configure whether metadata should be requested to be passed to the transform method.

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 (see sklearn.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 to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • 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

Xcstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for Xc parameter in transform.

ycstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for yc parameter in transform.

Returns

selfobject

The updated object.

transform(Xc: list, yc=None, **fit_params) array[source]

Transforms all datasets and concatenates the output.

Parameters:
  • Xc – list of datasets

  • yc – Only here to satisfy the scikit-learn API

Returns:

concatenated output

class skbel.preprocessing.composite.CompositeTransformer(base_function, **fit_params)[source]

Bases: TransformerMixin, BaseEstimator

__init__(base_function, **fit_params)[source]

Initiate the class by specifying a base scikit-learn object and the parameters to use for each dataset.

Parameters:
  • base_function – function to apply to the data

  • fit_params – parameters to pass to the base function

_sklearn_auto_wrap_output_keys = {'transform'}
fit(Xc: list, yc=None, **fit_params)[source]

Fit all transformations for the different datasets with their specified parameters.

Parameters:
  • Xc – list of datasets

  • yc – Only here to satisfy the scikit-learn API

Returns:

self

fit_transform(Xc: list, yc=None, **fit_params)[source]

Fit and transform all datasets.

Parameters:
  • Xc – list of datasets

  • yc – Only here to satisfy the scikit-learn API

Returns:

concatenated output

inverse_transform(Xr: array, yc=None, **fit_params) list[source]

Inverse transform the data back to the original space.

Parameters:
  • Xr – transformed data

  • yc – Only here to satisfy the scikit-learn API

Returns:

list of transformed datasets

set_fit_request(*, Xc: bool | None | str = '$UNCHANGED$', yc: bool | None | str = '$UNCHANGED$') CompositeTransformer

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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

Xcstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for Xc parameter in fit.

ycstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for yc parameter in fit.

Returns

selfobject

The updated object.

set_inverse_transform_request(*, Xr: bool | None | str = '$UNCHANGED$', yc: bool | None | str = '$UNCHANGED$') CompositeTransformer

Configure whether metadata should be requested to be passed to the inverse_transform method.

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 (see sklearn.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 to inverse_transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to inverse_transform.

  • 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

Xrstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for Xr parameter in inverse_transform.

ycstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for yc parameter in inverse_transform.

Returns

selfobject

The updated object.

set_transform_request(*, Xc: bool | None | str = '$UNCHANGED$', yc: bool | None | str = '$UNCHANGED$') CompositeTransformer

Configure whether metadata should be requested to be passed to the transform method.

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 (see sklearn.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 to transform if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to transform.

  • 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

Xcstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for Xc parameter in transform.

ycstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for yc parameter in transform.

Returns

selfobject

The updated object.

transform(Xc: list, yc=None, **fit_params) array[source]

Transforms all datasets and concatenates the output.

Parameters:
  • Xc – list of datasets

  • yc – Only here to satisfy the scikit-learn API

Returns:

concatenated output

class skbel.preprocessing.composite.Dummy[source]

Bases: TransformerMixin, MultiOutputMixin, BaseEstimator

Dummy transformer that does nothing.

__init__()[source]
_sklearn_auto_wrap_output_keys = {'transform'}
fit(X=None, y=None)[source]
fit_transform(X=None, y=None, **fit_params)[source]

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

Xarray-like of shape (n_samples, n_features)

Input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.

Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

inverse_transform(X=None, y=None)[source]
transform(X=None, y=None)[source]

skbel.preprocessing.dct

Discrete Cosine Transform written in scikit-learn style.

class skbel.preprocessing.dct.DiscreteCosineTransform2D(*, m_cut: int = None, n_cut: int = None)[source]

Bases: TransformerMixin, BaseEstimator

__init__(*, m_cut: int = None, n_cut: int = None)[source]
_sklearn_auto_wrap_output_keys = {'transform'}
fit(X, y)[source]
fit_transform(X, y=None, **fit_params)[source]

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

Xarray-like of shape (n_samples, n_features)

Input samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None

Target values (None for unsupervised transformations).

**fit_paramsdict

Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.

Returns

X_newndarray array of shape (n_samples, n_features_new)

Transformed array.

inverse_transform(X)[source]
transform(X)[source]