LocalAveragesTransformer#

class skfda.preprocessing.feature_construction.LocalAveragesTransformer(*, domains)[source]#

Transforms functional data to its local averages.

It takes functional data and performs the following map:

\[\begin{split}f_1(X) = \frac{1}{|T_1|} \int_{T_1} X(t) dt,\dots, \\ f_p(X) = \frac{1}{|T_p|} \int_{T_p} X(t) dt\end{split}\]

where \(T_1, \dots, T_p\) are subregions of the original domain.

Parameters:

domains (int | Sequence[int] | Sequence[DomainRangeLike]) – Domains for each local average. It is possible to pass a number or a list of numbers to automatically split each dimension in that number of intervals and use them for the averages.

See also

local_averages()

Examples

We import the Berkeley Growth Study dataset. We will use only the first 3 samples to make the example easy.

>>> from skfda.datasets import fetch_growth
>>> dataset = fetch_growth(return_X_y=True)[0]
>>> X = dataset[:3]

We can choose the intervals used for the local averages. For example, we could in this case use the averages at different stages of development of the child: from 1 to 3 years, from 3 to 10 and from 10 to 18:

>>> import numpy as np
>>> from skfda.preprocessing.feature_construction import (
...     LocalAveragesTransformer,
... )
>>> local_averages = LocalAveragesTransformer(
...     domains=[(1, 3), (3, 10), (10, 18)],
... )
>>> np.round(local_averages.fit_transform(X), decimals=2)
array([[  91.37,  126.52,  179.02],
       [  87.51,  120.71,  158.81],
       [  86.36,  115.04,  156.37]])

A different possibility is to decide how many intervals we want to consider. For example, we could want to split the domain in 2 intervals of the same length.

>>> local_averages = LocalAveragesTransformer(domains=2)
>>> np.around(local_averages.fit_transform(X), decimals=2)
array([[ 116.94,  177.26],
       [ 111.86,  157.62],
       [ 107.29,  154.97]])

Methods

fit(X[, y])

fit_transform(X[, y])

Fit to data, then transform it.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

transform(X[, y])

Transform the provided data to its local averages.

fit(X, y=None)[source]#
Parameters:
  • self (SelfType) –

  • X (Input) –

  • y (Target | None) –

Return type:

SelfType

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:
  • 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 – Transformed array.

Return type:

ndarray array of shape (n_samples, n_features_new)

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

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 – Parameter names mapped to their values.

Return type:

dict

set_output(*, transform=None)#

Set output container.

See Introducing the set_output API for an example on how to use the API.

Parameters:

transform ({"default", "pandas"}, 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

New in version 1.4: “polars” option was added.

Returns:

self – Estimator instance.

Return type:

estimator instance

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:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance

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

Transform the provided data to its local averages.

Parameters:
  • X (FData) – FDataGrid with the samples that are going to be transformed.

  • y (object) – Unused.

Returns:

Array of shape (n_samples, n_intervals) including the transformed data.

Return type:

ndarray[Any, dtype[float64]]