NumberCrossingsTransformer#

class skfda.preprocessing.feature_construction.NumberCrossingsTransformer(*, levels=0, direction='all')[source]#

Transformer that works as an adapter for the number_up_crossings function.

Parameters:
  • levels (ArrayLike) – Sequence of numbers including the levels we want to consider for the crossings. By default it calculates zero-crossings.

  • direction (Literal['up', 'down', 'all']) – Whether to consider only up-crossings, down-crossings or both.

Example

For this example we will use a well known function so the correct functioning of this method can be checked. We will create and use a DataFrame with a sample extracted from the Bessel Function of first type and order 0. First of all we import the Bessel Function and create the X axis data grid. Then we create the FdataGrid. >>> from skfda.preprocessing.feature_construction import ( … NumberCrossingsTransformer, … ) >>> from scipy.special import jv >>> from skfda.representation import FDataGrid >>> import numpy as np >>> x_grid = np.linspace(0, 14, 14) >>> fd_grid = FDataGrid( … data_matrix=[jv([0], x_grid)], … grid_points=x_grid, … ) >>> fd_grid.data_matrix array([[[ 1. ], [ 0.73041066], [ 0.13616752], [-0.32803875], [-0.35967936], [-0.04652559], [ 0.25396879], [ 0.26095573], [ 0.01042895], [-0.22089135], [-0.2074856 ], [ 0.0126612 ], [ 0.20089319], [ 0.17107348]]])

Finally we evaluate the number of zero-upcrossings method with the FDataGrid created. >>> tf = NumberCrossingsTransformer(levels=0, direction=”up”) >>> tf.fit_transform(fd_grid) array([[2]])

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 using the number_up_crossings function.

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 using the number_up_crossings function.

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

  • y (object) –

Returns:

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

Return type:

ndarray[Any, dtype[int64]]