************************************** :py:mod:`wildboar.datasets.preprocess` ************************************** .. py:module:: wildboar.datasets.preprocess .. autoapi-nested-parse:: Utilities for preprocessing time series. .. !! processed by numpydoc !! Classes ------- .. autoapisummary:: wildboar.datasets.preprocess.Interpolate wildboar.datasets.preprocess.MaxAbsScale wildboar.datasets.preprocess.MinMaxScale wildboar.datasets.preprocess.Standardize wildboar.datasets.preprocess.Truncate Functions --------- .. autoapisummary:: wildboar.datasets.preprocess.interpolate wildboar.datasets.preprocess.maxabs_scale wildboar.datasets.preprocess.minmax_scale wildboar.datasets.preprocess.named_preprocess wildboar.datasets.preprocess.standardize wildboar.datasets.preprocess.truncate .. raw:: html
.. py:class:: Interpolate(method='linear') Interpolate missing (`np.nan`) values. :Parameters: **method** : str, optional The interpolation method to use. Default is "linear". .. rubric:: Notes If scipy < 1.4, valid `method` values include "linear", "pchip", and "cubic". Otherwise, `method` also supports "akima" and "makima". .. !! processed by numpydoc !! .. py:method:: fit(X, y=None) Fit the model to the provided data. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to fit the model. **y** : array-like, optional The target values. Ignored. :Returns: object Returns the instance of the fitted model. .. !! processed by numpydoc !! .. py:method:: fit_transform(X, y=None, **fit_params) 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: **X** : array-like of shape (n_samples, n_features) Input samples. **y** : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None Target values (None for unsupervised transformations). **\*\*fit_params** : dict Additional fit parameters. :Returns: **X_new** : ndarray array of shape (n_samples, n_features_new) Transformed array. .. !! processed by numpydoc !! .. py:method:: get_metadata_routing() Get metadata routing of this object. Please check :ref:`User Guide ` on how the routing mechanism works. :Returns: **routing** : MetadataRequest A :class:`~sklearn.utils.metadata_routing.MetadataRequest` encapsulating routing information. .. !! processed by numpydoc !! .. py:method:: get_params(deep=True) Get parameters for this estimator. :Parameters: **deep** : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators. :Returns: **params** : dict Parameter names mapped to their values. .. !! processed by numpydoc !! .. py:method:: set_output(*, transform=None) Set output container. See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` for an example on how to use the API. :Parameters: **transform** : {"default", "pandas", "polars"}, default=None Configure output of `transform` and `fit_transform`. - `"default"`: Default output format of a transformer - `"pandas"`: DataFrame output - `"polars"`: Polars output - `None`: Transform configuration is unchanged .. versionadded:: 1.4 `"polars"` option was added. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: set_params(**params) Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as :class:`~sklearn.pipeline.Pipeline`). The latter have parameters of the form ``__`` so that it's possible to update each component of a nested object. :Parameters: **\*\*params** : dict Estimator parameters. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: transform(X) Transform the data using the specified interpolation method. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to be transformed. :Returns: ndarray of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The transformed data after applying the interpolation method. .. !! processed by numpydoc !! .. py:class:: MaxAbsScale Scale each time series by its maximum absolute value. .. !! processed by numpydoc !! .. py:method:: fit(X, y=None) Fit the model to the provided data. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to fit the model. **y** : array-like, optional The target values. Ignored. :Returns: object Returns the instance of the fitted model. .. !! processed by numpydoc !! .. py:method:: fit_transform(X, y=None, **fit_params) 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: **X** : array-like of shape (n_samples, n_features) Input samples. **y** : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None Target values (None for unsupervised transformations). **\*\*fit_params** : dict Additional fit parameters. :Returns: **X_new** : ndarray array of shape (n_samples, n_features_new) Transformed array. .. !! processed by numpydoc !! .. py:method:: get_metadata_routing() Get metadata routing of this object. Please check :ref:`User Guide ` on how the routing mechanism works. :Returns: **routing** : MetadataRequest A :class:`~sklearn.utils.metadata_routing.MetadataRequest` encapsulating routing information. .. !! processed by numpydoc !! .. py:method:: get_params(deep=True) Get parameters for this estimator. :Parameters: **deep** : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators. :Returns: **params** : dict Parameter names mapped to their values. .. !! processed by numpydoc !! .. py:method:: set_output(*, transform=None) Set output container. See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` for an example on how to use the API. :Parameters: **transform** : {"default", "pandas", "polars"}, default=None Configure output of `transform` and `fit_transform`. - `"default"`: Default output format of a transformer - `"pandas"`: DataFrame output - `"polars"`: Polars output - `None`: Transform configuration is unchanged .. versionadded:: 1.4 `"polars"` option was added. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: set_params(**params) Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as :class:`~sklearn.pipeline.Pipeline`). The latter have parameters of the form ``__`` so that it's possible to update each component of a nested object. :Parameters: **\*\*params** : dict Estimator parameters. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: transform(X) Transform the data using the specified interpolation method. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to be transformed. :Returns: ndarray of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The transformed data after applying the interpolation method. .. !! processed by numpydoc !! .. py:class:: MinMaxScale(min=0, max=1) Normalize time series, ensuring that each value within a specified minimum and maximum range. :Parameters: **min** : float, optional The minimum value. **max** : float, optional The maximum value. .. rubric:: Examples >>> from wildboar.datasets import load_gun_point >>> from wildboar.datasets.preprocess import MinMaxScale >>> X, _ = load_gun_point() >>> MinMaxScale().fit_transform(X).shape (200, 150) .. !! processed by numpydoc !! .. py:method:: fit(X, y=None) Fit the model to the provided data. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to fit the model. **y** : array-like, optional The target values. Ignored. :Returns: object Returns the instance of the fitted model. .. !! processed by numpydoc !! .. py:method:: fit_transform(X, y=None, **fit_params) 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: **X** : array-like of shape (n_samples, n_features) Input samples. **y** : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None Target values (None for unsupervised transformations). **\*\*fit_params** : dict Additional fit parameters. :Returns: **X_new** : ndarray array of shape (n_samples, n_features_new) Transformed array. .. !! processed by numpydoc !! .. py:method:: get_metadata_routing() Get metadata routing of this object. Please check :ref:`User Guide ` on how the routing mechanism works. :Returns: **routing** : MetadataRequest A :class:`~sklearn.utils.metadata_routing.MetadataRequest` encapsulating routing information. .. !! processed by numpydoc !! .. py:method:: get_params(deep=True) Get parameters for this estimator. :Parameters: **deep** : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators. :Returns: **params** : dict Parameter names mapped to their values. .. !! processed by numpydoc !! .. py:method:: set_output(*, transform=None) Set output container. See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` for an example on how to use the API. :Parameters: **transform** : {"default", "pandas", "polars"}, default=None Configure output of `transform` and `fit_transform`. - `"default"`: Default output format of a transformer - `"pandas"`: DataFrame output - `"polars"`: Polars output - `None`: Transform configuration is unchanged .. versionadded:: 1.4 `"polars"` option was added. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: set_params(**params) Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as :class:`~sklearn.pipeline.Pipeline`). The latter have parameters of the form ``__`` so that it's possible to update each component of a nested object. :Parameters: **\*\*params** : dict Estimator parameters. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: transform(X) Transform the data using the specified interpolation method. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to be transformed. :Returns: ndarray of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The transformed data after applying the interpolation method. .. !! processed by numpydoc !! .. py:class:: Standardize Standardize time series with zero mean and unit standard deviation. .. !! processed by numpydoc !! .. py:method:: fit(X, y=None) Fit the model to the provided data. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to fit the model. **y** : array-like, optional The target values. Ignored. :Returns: object Returns the instance of the fitted model. .. !! processed by numpydoc !! .. py:method:: fit_transform(X, y=None, **fit_params) 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: **X** : array-like of shape (n_samples, n_features) Input samples. **y** : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None Target values (None for unsupervised transformations). **\*\*fit_params** : dict Additional fit parameters. :Returns: **X_new** : ndarray array of shape (n_samples, n_features_new) Transformed array. .. !! processed by numpydoc !! .. py:method:: get_metadata_routing() Get metadata routing of this object. Please check :ref:`User Guide ` on how the routing mechanism works. :Returns: **routing** : MetadataRequest A :class:`~sklearn.utils.metadata_routing.MetadataRequest` encapsulating routing information. .. !! processed by numpydoc !! .. py:method:: get_params(deep=True) Get parameters for this estimator. :Parameters: **deep** : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators. :Returns: **params** : dict Parameter names mapped to their values. .. !! processed by numpydoc !! .. py:method:: set_output(*, transform=None) Set output container. See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` for an example on how to use the API. :Parameters: **transform** : {"default", "pandas", "polars"}, default=None Configure output of `transform` and `fit_transform`. - `"default"`: Default output format of a transformer - `"pandas"`: DataFrame output - `"polars"`: Polars output - `None`: Transform configuration is unchanged .. versionadded:: 1.4 `"polars"` option was added. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: set_params(**params) Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as :class:`~sklearn.pipeline.Pipeline`). The latter have parameters of the form ``__`` so that it's possible to update each component of a nested object. :Parameters: **\*\*params** : dict Estimator parameters. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: transform(X) Transform the data using the specified interpolation method. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to be transformed. :Returns: ndarray of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The transformed data after applying the interpolation method. .. !! processed by numpydoc !! .. py:class:: Truncate A transformer that truncates the input data based on the end of series indicators. .. !! processed by numpydoc !! .. py:method:: fit(X, y=None) Fit the model to the provided data. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to fit the model. **y** : array-like, optional The target values. Ignored. :Returns: object Returns the instance of the fitted model. .. !! processed by numpydoc !! .. py:method:: fit_transform(X, y=None, **fit_params) 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: **X** : array-like of shape (n_samples, n_features) Input samples. **y** : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None Target values (None for unsupervised transformations). **\*\*fit_params** : dict Additional fit parameters. :Returns: **X_new** : ndarray array of shape (n_samples, n_features_new) Transformed array. .. !! processed by numpydoc !! .. py:method:: get_metadata_routing() Get metadata routing of this object. Please check :ref:`User Guide ` on how the routing mechanism works. :Returns: **routing** : MetadataRequest A :class:`~sklearn.utils.metadata_routing.MetadataRequest` encapsulating routing information. .. !! processed by numpydoc !! .. py:method:: get_params(deep=True) Get parameters for this estimator. :Parameters: **deep** : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators. :Returns: **params** : dict Parameter names mapped to their values. .. !! processed by numpydoc !! .. py:method:: set_output(*, transform=None) Set output container. See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py` for an example on how to use the API. :Parameters: **transform** : {"default", "pandas", "polars"}, default=None Configure output of `transform` and `fit_transform`. - `"default"`: Default output format of a transformer - `"pandas"`: DataFrame output - `"polars"`: Polars output - `None`: Transform configuration is unchanged .. versionadded:: 1.4 `"polars"` option was added. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: set_params(**params) Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as :class:`~sklearn.pipeline.Pipeline`). The latter have parameters of the form ``__`` so that it's possible to update each component of a nested object. :Parameters: **\*\*params** : dict Estimator parameters. :Returns: **self** : estimator instance Estimator instance. .. !! processed by numpydoc !! .. py:method:: transform(X) Transform the input data X according to the fitted model. :Parameters: **X** : array-like Input data to transform. :Returns: array-like Transformed input data. .. !! processed by numpydoc !! .. py:function:: interpolate(X, method='linear') Interpolate the given time series using the specified method. :Parameters: **X** : array-like of shape (n_samples, n_dims, n_timestep) or (n_samples, n_timestep) The input data to be interpolated. It can be of any shape but must have at least dimension. **method** : str, optional The interpolation method to use. Default is "linear". :Returns: ndarray The interpolated data. .. rubric:: Notes If scipy < 1.4, valid `method` values include "linear", "pchip", and "cubic". Otherwise, `method` also supports "akima" and "makima". .. !! processed by numpydoc !! .. py:function:: maxabs_scale(x) Scale each time series by its maximum absolute value. :Parameters: **x** : ndarray of shape (n_samples, n_timestep) or (n_samples, n_dims, n_timestep) The samples. :Returns: ndarray of shape (n_samples, n_timestep) or (n_samples, n_dims, n_timestep) The transformed samples. .. !! processed by numpydoc !! .. py:function:: minmax_scale(x, min=0, max=1) Scale x along the time dimension. Each time series is scaled such that each value is between min and max. :Parameters: **x** : ndarray of shape (n_samples, n_timestep) or (n_samples, n_dims, n_timestep) The samples. **min** : float, optional The minimum value. **max** : float, optional The maximum value. :Returns: ndarray of shape (n_samples, n_timestep) or (n_samples, n_dims, n_timestep) The transformed samples. .. !! processed by numpydoc !! .. py:function:: named_preprocess(name) Get a named preprocessor. :Parameters: **name** : str The name of the preprocessor. :Returns: callable The preprocessor function. .. !! processed by numpydoc !! .. py:function:: standardize(x) Scale x along the time dimension. The resulting array will have zero mean and unit standard deviation. :Parameters: **x** : ndarray of shape (n_samples, n_timestep) or (n_samples, n_dims, n_timestep) The samples. :Returns: ndarray of shape (n_samples, n_timestep) or (n_samples, n_dims, n_timestep) The standardized samples. .. !! processed by numpydoc !! .. py:function:: truncate(x) Truncate x to the shortest sequence. :Parameters: **x** : ndarray of shape (n_samples, n_timestep) or (n_samples, n_dims, n_timestep) The samples. :Returns: ndarray of shape (n_samples, n_shortest) or (n_samples, n_dims, n_shortest) The truncated samples. .. !! processed by numpydoc !!