giotto.time_series
.Labeller¶
-
class
giotto.time_series.
Labeller
(width=10, func=<function std>, func_params={}, percentiles=None, n_steps_future=1)¶ Target creation from sliding windows over a time series.
Useful to define a time series forecasting task in which labels are obtained from future values of the input time series, via the application of a function to time windows.
- Parameters
- widthint, optional, default:
10
Width of each sliding window. Each window contains
width + 1
objects from the original time series.- funccallable, optional, default:
numpy.std
Function to be applied to each window.
- func_paramsdict, optional, default:
{}
Additional keyword arguments for func.
- percentileslist of ordered floats between 0 and 1 or None, optional, default:
None
If
None
, creates a target for a regression task. Otherwise, creates a target for an n-class classification task wheren = len(percentiles) + 1
.- n_steps_futureint, optional, default:
1
Number of steps in the future for the predictive task.
- widthint, optional, default:
- Attributes
- thresholds_list of floats or
None
if percentiles isNone
Values corresponding to each percentile, based on data seen in
fit
.
- thresholds_list of floats or
Examples
>>> import numpy as np >>> from giotto.time_series import Labeller >>> # Create a time series >>> X = np.arange(10).reshape(-1, 1) >>> labeller = Labeller(width=2) >>> # Fit and transform X >>> X, y = labeller.fit_transform_resample(X, X) >>> print(X) [[1] [2] [3] [4] [5] [6] [7] [8]] >>> print(y) [0.81649658 0.81649658 0.81649658 0.81649658 0.81649658 0.81649658 0.81649658 0.81649658]
Methods
fit
(self, X[, y])Compute
thresholds_
and return the estimator.fit_transform
(self, X[, y])Fit to data, then transform it.
fit_transform_resample
(self, X, y, …)Fit to data, then transform the input and resample the target.
get_params
(self[, deep])Get parameters for this estimator.
resample
(self, y[, X])Resample y.
set_params
(self, \*\*params)Set the parameters of this estimator.
transform
(self, X[, y])Cuts X so it is aligned with y.
transform_resample
(self, X, y)Fit to data, then transform it.
-
__init__
(self, width=10, func=<function std at 0x10f7bfe18>, func_params={}, percentiles=None, n_steps_future=1)¶ Initialize self. See help(type(self)) for accurate signature.
-
fit
(self, X, y=None)¶ Compute
thresholds_
and return the estimator.- Parameters
- Xndarray, shape (n_samples,) or (n_samples, 1)
Time series to build a target for.
- yNone
There is no need for a target in a transformer, yet the pipeline API requires this parameter.
- Returns
- selfobject
-
fit_transform
(self, 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
- Xndarray of shape (n_samples, …)
Input data.
- yNone
There is no need for a target in a transformer, yet the pipeline API requires this parameter.
- Returns
- Xtnumpy array of shape (n_samples, …)
Transformed input.
-
fit_transform_resample
(self, 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
- Xndarray of shape (n_samples, …)
Input data.
- yndarray of shape (n_samples, )
Target data.
- Returns
- Xtndarray of shape (n_samples, …)
Transformed input.
- yrndarray of shape (n_samples, …)
Resampled target.
-
get_params
(self, deep=True)¶ Get parameters for this estimator.
- Parameters
- deepboolean, optional
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
- paramsmapping of string to any
Parameter names mapped to their values.
-
resample
(self, y, X=None)¶ Resample y.
- Parameters
- yndarray, shape (n_samples,)
Time series to build a target for.
- XNone
There is no need for X, yet the pipeline API requires this parameter.
- Returns
- yrndarray, shape (n_samples_new,)
Target for the prediction task.
-
set_params
(self, **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.- Returns
- self
-
transform
(self, X, y=None)¶ Cuts X so it is aligned with y.
- Parameters
- Xndarray, shape (n_samples,) or (n_samples, 1)
Time series to build a target for.
- yNone
There is no need for a target, yet the pipeline API requires this parameter.
- Returns
- Xtndarray, shape (n_samples_new, 1)
The cut input time series.
-
transform_resample
(self, 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
- Xndarray of shape (n_samples, …)
Input data.
- yndarray of shape (n_samples, )
Target data.
- Returns
- Xtndarray of shape (n_samples, …)
Transformed input.