Impute

async AsyncCogniteClient.ai.time_series.impute(
time_series: ForecastInputTimeSeries | Sequence[ForecastInputTimeSeries],
) → ImputeResult | ImputeResultList

Predict the value of every datapoint marked missing, from the datapoints on both sides of it.

Use it to fill gaps: mark the datapoints in a gap as missing, and use the predicted median. Or use it to detect anomalies: mark observed datapoints as missing, and compare each observed value with its predicted quantiles. The API doesn’t decide what is anomalous. Time series in the same cohort are imputed jointly, so the model can also use the other time series in the cohort.

Note

A datapoint marked missing is hidden from the model, whatever its value, and returned. A datapoint with value None and not marked missing is hidden from the model but not returned.

This endpoint is in beta, and is called with the beta cdf-version header.

Parameters:

time_series (ForecastInputTimeSeries | Sequence[ForecastInputTimeSeries]) – The time series, with the datapoints to predict marked missing. They have the same requirements as in forecast.

Returns:

The result for a single time series, or one result per time series, in

input order, with one point per datapoint marked missing. Use the 0.5 quantile, the median, as a single predicted value.

Return type:

ImputeResult | ImputeResultList

Raises:

ValueError – If a label is repeated, a cohort has more than 32 time series, or a time series or cohort is over 5 MiB on its own. These are the API’s limits for one request, and a cohort is always sent in one request.

Examples

Fill a one-point gap, and get the predicted median:

>>> from cognite.client import CogniteClient, AsyncCogniteClient
>>> from cognite.client.data_classes.ai import (
...     ForecastInputDatapoint,
...     ForecastInputTimeSeries,
... )
>>> client = CogniteClient()
>>> # async_client = AsyncCogniteClient()  # another option
>>> series = ForecastInputTimeSeries(
...     "21-PT-1019",
...     [
...         ForecastInputDatapoint(0, 42.1),
...         ForecastInputDatapoint(60_000, None, missing=True),
...         ForecastInputDatapoint(120_000, 42.9),
...     ],
... )
>>> res = client.ai.time_series.impute(series)
>>> median = res.to_pandas()["21-PT-1019"]