TabularToSeriesAdaptor
TabularToSeriesAdaptor
- class TabularToSeriesAdaptor(transformer, fit_in_transform=False, pass_y='auto', input_type=None, pooling='local')[source]
Adapt scikit-learn transformation interface to time series setting.
This is useful for applying scikit-learn tabular transformations to series, but only works with transformations that do not require multiple instances for fitting.
The adaptor behaves as follows.
If
fit_in_transform = FalseandXis a series (pd.DataFrame,pd.Series,np.ndarray):fit(X)fits a clone oftransformerto X (considered as a table)transform(X)applies transformer.transform to X and returns the resultinverse_transform(X)appliestransformer.inverse_transformtoX
If
fit_in_transform = TrueandXis a series (pd.DataFrame,pd.Series,np.ndarray):fitis emptytransform(X)appliestransformer.fit(X).transform(X)toX, considered as a table, and returns the resultinverse_transform(X)appliestransformer.fit(X).inverse_transform(X)toX
- If
fit_in_transform = False, andXis of a panel/hierarchical type: fit(X)fits a clone oftransformerfor each individual seriesxinXtransform(X)appliestransform(x)of the clone belonging tox(where the index of x in transform equals the index of x in fit), for each individual seriesxinX, and returns the resultinverse_transform(X)appliestransform(x)of the clone belonging tox(where the index of x in transform equals the index ofxin fit), for each individual seriesxinX, and returns the resultNote: instances indices in
transform/inverse_transformmust be equal to those seen infit
- If
fit_in_transform = True, andXis of a panel/hierarchical type: fitis emptytransform(X)appliestransformer.fit(x).transform(x)to all individual seriesxinXand returns the resultinverse_transform(X)appliestransformer.fit(x).inverse_transform(x)to all individual seriesxinXand returns the result
- WARNING: if
fit_in_transformis set toFalse, when applied to Panel or Hierarchical data, the resulting transformer will identify individual series in test set with series indices in training set, on which instances were fit in particular, transform will not work if number of instances and indices of instances in transform are different from those in fit
- WARNING: if
fit_in_transformis set toTrue, then each series in the test set will be transformed as batch by fit-predict, this may cause information leakage in a forecasting setting (but not in a time series classification/regression/clustering setting, because in these settings the independent samples are the individual series)
Whether
yis passed to transformer methods is controlled bypass_y. If the inner transformer has non-defaultingyargs, the default behaviour is to passytofit,fit_transform, ortransform. If noyarg is present, or if it has a default value,yis not passed.If the passed transformer accepts only
yinfitandtransform, thenpass_yis ignored, andXis plugged into theyargument.- Parameters:
- transformer
sklearntransformer,BaseEstimatordescendant instance scikit-learn-like transformer to fit and apply to series. This is used as a “blueprint” and not fitted or otherwise mutated.
- fit_in_transform: bool, optional, default=False
whether transformer_ should be fitted in transform (True), or in fit (False).
recommended setting in forecasting (single series or hierarchical):
Falserecommended setting in ts classification, regression, clustering:
True
- pass_ystr, optional, one of “auto” (default), “fit”, “always”, “never”
Whether to pass y to transformer methods of the
transformerclone.“auto”: passes
yto methodsfit,transform,fit_transform,inverse_transform, if and only ifyis a named arg of either method without default. Note: passesyeven if it isNone“fit”: passes
yto methodfit, but not totransform. Note: passesyeven if it isNone, or if not a named arg“always”: passes
yto all methods,fit,transform,inverse_transform. Note: passesyeven if it isNone, or if not a named arg“never”: never passes
yto any method.
- input_typestr, one of “numpy” (default), “pandas”, optional
type of data passed to the
sklearntransformer“numpy”: 2D
np.ndarray“pandas”:
pd.DataFrame, with column names passed to transformer. column names are coerced to strings if not already, row index is reset toRangeIndex.
- poolingstr, one of “local” (default), “global”
whether to apply transformer to each series individually (local), or to all series at once (global)
“local”: applies transformer to each series individually
“global”: applies transformer to all series at once, pooled to a single 2D
np.ndarrayorpd.DataFrame
- transformer
- Attributes:
- transformer_Estimator
Transformer that is fitted to data, clone of transformer.
Examples
>>> from sktime.transformations.adapt import TabularToSeriesAdaptor >>> from sklearn.preprocessing import MinMaxScaler >>> from sktime.datasets import load_airline >>> y = load_airline() >>> transformer = TabularToSeriesAdaptor(MinMaxScaler()) >>> y_hat = transformer.fit_transform(y)
Methods
check_is_fitted([method_name])Check if the estimator has been fitted.
clone()Obtain a clone of the object with same hyper-parameters and config.
clone_tags(estimator[, tag_names])Clone tags from another object as dynamic override.
create_test_instance([parameter_set])Construct an instance of the class, using first test parameter set.
create_test_instances_and_names([parameter_set])Create list of all test instances and a list of names for them.
fit(X[, y])Fit transformer to X, optionally to y.
fit_transform(X[, y])Fit to data, then transform it.
get_class_tag(tag_name[, tag_value_default])Get class tag value from class, with tag level inheritance from parents.
get_class_tags()Get class tags from class, with tag level inheritance from parent classes.
get_config()Get config flags for self.
get_fitted_params([deep])Get fitted parameters.
get_param_defaults()Get object's parameter defaults.
get_param_names([sort])Get object's parameter names.
get_params([deep])Get a dict of parameters values for this object.
get_tag(tag_name[, tag_value_default, ...])Get tag value from instance, with tag level inheritance and overrides.
get_tags()Get tags from instance, with tag level inheritance and overrides.
get_test_params([parameter_set])Return testing parameter settings for the estimator.
inverse_transform(X[, y])Inverse transform X and return an inverse transformed version.
is_composite()Check if the object is composed of other BaseObjects.
load_from_path(serial)Load object from file location.
load_from_serial(serial)Load object from serialized memory container.
reset()Reset the object to a clean post-init state.
save([path, serialization_format])Save serialized self to bytes-like object or to (.zip) file.
set_config(**config_dict)Set config flags to given values.
set_params(**params)Set the parameters of this object.
set_random_state([random_state, deep, ...])Set random_state pseudo-random seed parameters for self.
set_tags(**tag_dict)Set instance level tag overrides to given values.
transform(X[, y])Transform X and return a transformed version.
update(X[, y, update_params])Update transformer with X, optionally y.

