sktime.transformations.series.detrend¶
-
class
sktime.transformations.series.detrend.
ConditionalDeseasonalizer
(seasonality_test=None, sp=1, model='additive')[source]¶ Bases:
sktime.transformations.series.detrend._deseasonalize.Deseasonalizer
A transformer that removes a seasonal and trend components from time series, conditional on seasonality test.
- Parameters
seasonality_test (callable, optional (default=None)) – Callable that tests for seasonality and returns True when data is seasonal and False otherwise. If None, 90% autocorrelation seasonality test is used.
sp (int, optional (default=1)) – Seasonal periodicity
model (str {"additive", "multiplicative"}, optional (default="additive")) – Model to use for estimating seasonal component
-
class
sktime.transformations.series.detrend.
Deseasonalizer
(sp=1, model='additive')[source]¶ Bases:
sktime.transformations.base._SeriesToSeriesTransformer
A transformer that removes a seasonal and trend components from time series
- Parameters
sp (int, optional (default=1)) – Seasonal periodicity
model (str {"additive", "multiplicative"}, optional (default="additive")) – Model to use for estimating seasonal component
-
fit
(Z, X=None)[source]¶ Fit to data.
- Parameters
Z (pd.Series) –
X (pd.DataFrame) –
- Returns
self
- Return type
an instance of self
-
inverse_transform
(Z, X=None)[source]¶ Inverse transform data. Returns a transformed version of y.
- Parameters
y (pd.Series) –
X (pd.DataFrame) –
- Returns
yt – Transformed time series.
- Return type
pd.Series
-
class
sktime.transformations.series.detrend.
Detrender
(forecaster)[source]¶ Bases:
sktime.transformations.base._SeriesToSeriesTransformer
Remove a trend from a series. This transformer uses any forecaster and returns the in-sample residuals of the forecaster’s predicted values.
The Detrender works by first fitting the forecaster to the input data. To transform data, it uses the fitted forecaster to generate forecasts for the time points of the passed data and returns the residuals
of the forecasts.
Depending on the passed data, this will require it to generate in-sample or out-of-sample forecasts.
The detrender also works in a pipeline as a form of boosting, by first detrending a time series and then fitting another forecaster on the residuals.
For example, to remove the linear trend of a time series: forecaster = PolynomialTrendForecaster(degree=1) transformer = Detrender(forecaster=forecaster) yt = transformer.fit_transform(y_train)
- Parameters
forecaster (estimator object) – The forecasting model to remove the trend with (e.g. PolynomialTrendForecaster)
-
fit
(Z, X=None)[source]¶ Compute the trend in the series
- Parameters
Y (pd.Series) – Endogenous time series to fit a trend to.
X (pd.DataFrame, optional (default=None)) – Exogenous variables
- Returns
self
- Return type
an instance of self
-
inverse_transform
(Z, X=None)[source]¶ Add trend back to a time series
- Parameters
y (pd.Series, list) – Detrended time series to revert
X (pd.DataFrame, optional (default=False)) – Exogenous variables
- Returns
y_hat – Series with the trend
- Return type
pd.Series
-
transform
(Z, X=None)[source]¶ Remove trend from the data.
- Parameters
y (pd.Series) – Time series to be detrended
X (pd.DataFrame, optional (default=False)) – Exogenous variables
- Returns
y_hat – De-trended series
- Return type
pd.Series
-
update
(Z, X=None, update_params=True)[source]¶ Update the parameters of the detrending estimator with new data
- Parameters
y_new (pd.Series) – New time series
update_params (bool, optional (default=True)) – Update the parameters of the detrender model with
- Returns
self
- Return type
an instance of self