Resampler¶
-
class
gtda.time_series.
Resampler
(period=2)[source]¶ Time series resampling at regular intervals.
- Parameters
period (int, default:
2
) – The sampling period, i.e. one point every period will be kept.
Examples
>>> import numpy as np >>> from gtda.time_series import Resampler >>> # Create a noisy signal >>> signal = np.asarray([np.sin(x /40) + np.random.random() ... for x in range(0, 300)]) >>> # Set up the Resampler >>> period = 10 >>> periodic_sampler = Resampler(period=period) >>> # Fit and transform the signal >>> signal_resampled = periodic_sampler.fit_transform(signal) >>> print(signal_resampled.shape) (30,)
-
fit
(X, y=None)[source]¶ Do nothing and return the estimator unchanged.
This method is here to implement the usual scikit-learn API and hence work in pipelines.
- Parameters
X (ndarray of shape (n_samples,) or (n_samples, ..)) – Input data.
y (None) – Ignored.
- Returns
self
- Return type
object
-
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 (ndarray of shape (n_samples,) or (n_samples, ..)) – Input data.
y (None) – Ignored.
- Returns
Xt – Resampled array.
n_samples_new = n_samples // period
.- Return type
ndarray of shape (n_samples_new, ..)
-
fit_transform_resample
(X, y, **fit_params)¶ Fit to data, then transform the input and resample the target. Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X ans a resampled version of y.
- Parameters
X (ndarray of shape (n_samples, ..)) – Input data.
y (ndarray of shape (n_samples,)) – Target data.
- Returns
Xt (ndarray of shape (n_samples, …)) – Transformed input.
yr (ndarray of shape (n_samples, …)) – Resampled target.
-
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
mapping of string to any
-
resample
(y, X=None)[source]¶ Resample y.
- Parameters
y (ndarray of shape (n_samples,)) – Target.
X (None) – There is no need for input data, yet the pipeline API requires this parameter.
- Returns
yr – Resampled target.
n_samples_new = n_samples // period
.- Return type
ndarray of shape (n_samples_new,)
-
set_params
(**params)¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). 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
object
-
transform
(X, y=None)[source]¶ Resample X.
- Parameters
X (ndarray of shape (n_samples,) or (n_samples, ..)) – Input data.
y (None) – There is no need for a target, yet the pipeline API requires this parameter.
- Returns
Xt – Resampled array.
n_samples_new = n_samples // period
.- Return type
ndarray of shape (n_samples_new, ..)
-
transform_resample
(X, y)¶ 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 (ndarray of shape (n_samples, ..)) – Input data.
y (ndarray of shape (n_samples,)) – Target data.
- Returns
Xt (ndarray of shape (n_samples, …)) – Transformed input.
yr (ndarray of shape (n_samples, …)) – Resampled target.