HierarchicalPipeline¶
- class HierarchicalPipeline(reconciliator: etna.reconciliation.base.BaseReconciliator, model: Union[etna.models.base.NonPredictionIntervalContextIgnorantAbstractModel, etna.models.base.NonPredictionIntervalContextRequiredAbstractModel, etna.models.base.PredictionIntervalContextIgnorantAbstractModel, etna.models.base.PredictionIntervalContextRequiredAbstractModel], transforms: Sequence[etna.transforms.base.Transform] = (), horizon: int = 1)[source]¶
Bases:
etna.pipeline.pipeline.Pipeline
Pipeline of transforms with a final estimator for hierarchical time series data.
Notes
Aggregation of target quantiles and components is performed along with the target itself. It uses a provided hierarchical structure and a reconciliation method.
Create instance of HierarchicalPipeline with given parameters.
- Parameters
reconciliator (etna.reconciliation.base.BaseReconciliator) – Instance of reconciliation method
model (Union[etna.models.base.NonPredictionIntervalContextIgnorantAbstractModel, etna.models.base.NonPredictionIntervalContextRequiredAbstractModel, etna.models.base.PredictionIntervalContextIgnorantAbstractModel, etna.models.base.PredictionIntervalContextRequiredAbstractModel]) – Instance of the etna Model
transforms (Sequence[etna.transforms.base.Transform]) – Sequence of the transforms
horizon (int) – Number of timestamps in the future for forecasting
Warning
Estimation of forecast intervals with forecast(prediction_interval=True) method and BottomUpReconciliator may be not reliable.
- Inherited-members
- Parameters
reconciliator (etna.reconciliation.base.BaseReconciliator) –
model (Union[etna.models.base.NonPredictionIntervalContextIgnorantAbstractModel, etna.models.base.NonPredictionIntervalContextRequiredAbstractModel, etna.models.base.PredictionIntervalContextIgnorantAbstractModel, etna.models.base.PredictionIntervalContextRequiredAbstractModel]) –
transforms (Sequence[etna.transforms.base.Transform]) –
horizon (int) –
Methods
backtest
(ts, metrics[, n_folds, mode, ...])Run backtest with the pipeline.
fit
(ts)Fit the HierarchicalPipeline.
forecast
([ts, prediction_interval, ...])Make a forecast of the next points of a dataset at a target level.
load
(path[, ts])Load an object.
params_to_tune
()Get hyperparameter grid to tune.
predict
([ts, start_timestamp, ...])Make in-sample predictions on dataset at the target level in a given range.
raw_forecast
(ts[, prediction_interval, ...])Make a forecast of the next points of a dataset at the source level.
raw_predict
(ts[, start_timestamp, ...])Make in-sample predictions on dataset at the source level in a given range.
save
(path)Save the object.
set_params
(**params)Return new object instance with modified parameters.
to_dict
()Collect all information about etna object in dict.
Attributes
- fit(ts: etna.datasets.tsdataset.TSDataset) etna.pipeline.hierarchical_pipeline.HierarchicalPipeline [source]¶
Fit the HierarchicalPipeline.
Fit and apply given transforms to the data, then fit the model on the transformed data. Provided hierarchical dataset will be aggregated to the source level before fitting pipeline.
- Parameters
ts (etna.datasets.tsdataset.TSDataset) – Dataset with hierarchical timeseries data
- Returns
Fitted HierarchicalPipeline instance
- Return type
- forecast(ts: Optional[etna.datasets.tsdataset.TSDataset] = None, prediction_interval: bool = False, quantiles: Sequence[float] = (0.025, 0.975), n_folds: int = 3, return_components: bool = False) etna.datasets.tsdataset.TSDataset [source]¶
Make a forecast of the next points of a dataset at a target level.
The result of forecasting starts from the last point of
ts
, not including it.Method makes a prediction for target at the source level of hierarchy and then makes reconciliation to target level.
- Parameters
ts (Optional[etna.datasets.tsdataset.TSDataset]) – Dataset to forecast. If not given, dataset given during :py:meth:
fit
is used.prediction_interval (bool) – If True returns prediction interval for forecast
quantiles (Sequence[float]) – Levels of prediction distribution. By default 2.5% and 97.5% taken to form a 95% prediction interval
n_folds (int) – Number of folds to use in the backtest for prediction interval estimation
return_components (bool) – If True additionally returns forecast components
- Returns
Dataset with predictions at the target level of hierarchy.
- Return type
- classmethod load(path: pathlib.Path, ts: Optional[etna.datasets.tsdataset.TSDataset] = None) etna.pipeline.hierarchical_pipeline.HierarchicalPipeline [source]¶
Load an object.
- Parameters
path (pathlib.Path) – Path to load object from.
ts (Optional[etna.datasets.tsdataset.TSDataset]) – TSDataset to set into loaded pipeline.
- Returns
Loaded object.
- Return type
- predict(ts: Optional[etna.datasets.tsdataset.TSDataset] = None, start_timestamp: Optional[pandas._libs.tslibs.timestamps.Timestamp] = None, end_timestamp: Optional[pandas._libs.tslibs.timestamps.Timestamp] = None, prediction_interval: bool = False, quantiles: Sequence[float] = (0.025, 0.975), return_components: bool = False) etna.datasets.tsdataset.TSDataset [source]¶
Make in-sample predictions on dataset at the target level in a given range.
Method makes a prediction for target at the source level of hierarchy and then makes reconciliation to the target level.
Currently, in situation when segments start with different timestamps we only guarantee to work with
start_timestamp
>= beginning of all segments.- Parameters
ts (Optional[etna.datasets.tsdataset.TSDataset]) – Dataset to make predictions on. If not given, dataset given during :py:meth:
fit
is used.start_timestamp (Optional[pandas._libs.tslibs.timestamps.Timestamp]) – First timestamp of prediction range to return, should be >= than first timestamp in
ts
; expected that beginning of each segment <=start_timestamp
; if isn’t set the first timestamp where each segment began is taken.end_timestamp (Optional[pandas._libs.tslibs.timestamps.Timestamp]) – Last timestamp of prediction range to return; if isn’t set the last timestamp of
ts
is taken. Expected that value is less or equal to the last timestamp ints
.prediction_interval (bool) – If True returns prediction interval for forecast.
quantiles (Sequence[float]) – Levels of prediction distribution. By default 2.5% and 97.5% taken to form a 95% prediction interval.
return_components (bool) – If True additionally returns forecast components.
- Returns
Dataset with predictions at the target level in
[start_timestamp, end_timestamp]
range.- Return type
- raw_forecast(ts: etna.datasets.tsdataset.TSDataset, prediction_interval: bool = False, quantiles: Sequence[float] = (0.25, 0.75), n_folds: int = 3, return_components: bool = False) etna.datasets.tsdataset.TSDataset [source]¶
Make a forecast of the next points of a dataset at the source level.
The result of forecasting starts from the last point of
ts
, not including it.- Parameters
ts (etna.datasets.tsdataset.TSDataset) – Dataset to forecast
prediction_interval (bool) – If True returns prediction interval for forecast
quantiles (Sequence[float]) – Levels of prediction distribution. By default 2.5% and 97.5% taken to form a 95% prediction interval
n_folds (int) – Number of folds to use in the backtest for prediction interval estimation
return_components (bool) – If True additionally returns forecast components
- Returns
Dataset with predictions at the source level
- Return type
- raw_predict(ts: etna.datasets.tsdataset.TSDataset, start_timestamp: Optional[pandas._libs.tslibs.timestamps.Timestamp] = None, end_timestamp: Optional[pandas._libs.tslibs.timestamps.Timestamp] = None, prediction_interval: bool = False, quantiles: Sequence[float] = (0.025, 0.975), return_components: bool = False) etna.datasets.tsdataset.TSDataset [source]¶
Make in-sample predictions on dataset at the source level in a given range.
- Parameters
ts (etna.datasets.tsdataset.TSDataset) – Dataset to make predictions on. If not given, dataset given during :py:meth:
fit
is used.start_timestamp (Optional[pandas._libs.tslibs.timestamps.Timestamp]) – First timestamp of prediction range to return, should be >= than first timestamp in
ts
; expected that beginning of each segment <=start_timestamp
; if isn’t set the first timestamp where each segment began is taken.end_timestamp (Optional[pandas._libs.tslibs.timestamps.Timestamp]) – Last timestamp of prediction range to return; if isn’t set the last timestamp of
ts
is taken. Expected that value is less or equal to the last timestamp ints
.prediction_interval (bool) – If True returns prediction interval for forecast.
quantiles (Sequence[float]) – Levels of prediction distribution. By default 2.5% and 97.5% taken to form a 95% prediction interval.
return_components (bool) – If True additionally returns forecast components.
- Returns
Dataset with predictions at the source level in
[start_timestamp, end_timestamp]
range.- Return type