etna
etna copied to clipboard
Add `predict` method to pipelines
🚀 Feature Request
Add method predict
to pipelines.
Motivation
Introduce more flexible ways of forecasting to our architecture.
Proposal
This task is blocked by #783.
Add a method to AbstractPipeline
:
def predict(self, ts: Optional[TSDataset] = None, start_timestamp: Optional[pd.Timestamp] = None, end_timestamp: Optional[pd.Timestamp] = None, prediction_interval: bool = False, quantiles: Sequence[float] = (0.025, 0.975)) -> TSDataset:
"""
Make predictions in a given range.
Parameters
----------
ts:
dataset with context, if isn't present ``self.ts`` is used
start_timestamp:
first timestamp of prediction range to return, should be >= than first timestamp in ``ts``;
expected that beginning of each segment <= ``start_timestamp``
end_timestamp:
last timestamp of prediction range to return
prediction_interval:
If True returns prediction interval for forecast
quantiles:
Levels of prediction distribution. By default 2.5% and 97.5% taken to form a 95% prediction interval
Returns
-------
:
Dataset with predictions in ``[start_timestamp, end_timestamp]`` range.
"""
Details:
-
ts
doesn't contain all the features, transforms will be applied duringpredict
- If
ts
isn't set check presense ofself.ts
and try to use it. - If different segments start with different timestamp we have guarantee to work only with
start_timestamp
>= beginning of all segments. - If
start_timestamp
isn't set use first timestamp ints
. - If
end_timestamp
isn't set use last timestamp ints
. - Check that
end_timestamp
>=start_timestamp
. - If model fails during prediction (e.g. because of NaNs) we should let
predict
fail because of it.
Add implementation for BasePipeline
. It should:
- Check constraint on
ts
andstart_timestamp
. - Check
start_timestamp
,end_timestamp
values. - if
prediction_interval=True
check that this pipeline supports prediction interval and validatequantiles
. - call
_predict
method for getting actual predictions.
Pipelines that support prediction intervals:
-
Pipeline
with models that support prediction intervals. - Other cases can be added in the future.
Add empty implementation of BasePipeline._predict
, we will add it in the future.
Test cases
For all concrete pipelines add tests:
- Check that
predict
works correctly ifts
isn't set andself.ts
is present. - Check that
predict
fails ifts
isn't set andself.ts
isn't present. - Check that
predict
fails if the constraint betweents
andstart_timestamp
is broken. - Check that
predict
works correctly ifstart_timestamp
orend_timestamp
isn't set. - Check that
predict
fails ifend_timestamp
<start_timestamp
. - Check that
_predict
is called. - Check that if
prediction_interval=True
, checking pipeline support of intervals is called. - Check that if
prediction_interval=True
, function for quantiles validation is called.
Alternatives
No response
Additional context
No response
Checklist
- [x] I discussed this issue with ETNA Team