TransformIf
Conditional execution of a transformer given a condition from a fittable object.
Compositor to construct conditionally executed transformers, e.g.,
compute first differences if a stationarity test is positive
deseasonalize if a seasonality test is positive
This compositor allows to specify a condition, and an if/else transformer. The default “else” transformer is “no transformation”.
The specific algorithm implemented is as follows:
In fit, for inputs X, y: 1. fits if_estimator to X, y 2. checks the condition for if_estimator fitted parameter param:
whether param satisfies condition with condition_value
3. If yes, fits then_est to X, y, and behaves as then_est from then on
If no, fits else_est to X, y, and behaves as else_est from then on
In other methods, behaves as then_est or else_est, as above.
Note: then_trafo and else_trafo must have the same input/output signature, e.g., Series-to-Series, or Series-to-Primitives.
Schnellstart
from sktime.transformations.compose import TransformIf
estimator = TransformIf(if_estimator, param=None, condition='bool', condition_value=None, then_trafo=None, else_trafo=None)Parameter(6)
- if_estimatorsktime estimator, must have fit
sktime estimator to fit and apply to series. this is a “blueprint” estimator, state does not change when
fitis called- paramstr, optional, default = first boolean parameter of fitted if_estimator
- conditionstr, optional, default = “bool”
condition that defines whether self behaves like
then_estorelse_estthis estimator behaves likethen_estiff: “bool” = ifparamis True “>”, “>=”, “==”, “<”, “<=”, “!=” = ifparam condition condition_value- condition_valuerequired for some conditions, see above; otherwise optional
- then_trafosktime transformer, optional, default=``if_estimator``
transformer that this behaves as if condition is satisfied this is a “blueprint” transformer, state does not change when
fitis called- else_trafosktime transformer, optional default=``Id`` (identity/no transform)
transformer that this behaves as if condition is not satisfied this is a “blueprint” transformer, state does not change when
fitis called
Beispiele
>>> from sktime.param_est.seasonality import SeasonalityACF
>>> from sktime.transformations.compose import TransformIf
>>> from sktime.transformations.detrend import Deseasonalizer
>>> from sktime.datasets import load_airline
>>>
>>> y = load_airline ()
>>>
>>> seasonal = SeasonalityACF (candidate_sp = 12)
>>> deseason = Deseasonalizer (sp = 12)
>>> cond_deseason = TransformIf (seasonal, "sp", "!=", 1, deseason)
>>> y_hat = cond_deseason. fit_transform (y)