unit8co / darts

A python library for user-friendly forecasting and anomaly detection on time series.
https://unit8co.github.io/darts/
Apache License 2.0
7.91k stars 858 forks source link

Retrieve one sample of a probabilistic series as a TimeSeries #2464

Closed dwolffram closed 1 month ago

dwolffram commented 1 month ago

Hi there,

is there a simple way to retrieve one sample of a probabilistic series as a TimeSeries object? I only found univariate_values() which returns a 1-D Numpy array.

Thanks!

dennisbader commented 1 month ago

Hi @dwolffram, yes there are a couple of ways:

dwolffram commented 1 month ago

Thanks @dennisbader but these all return a numpy.ndarray and not a TimeSeries.

In the case of a multivariate series, you can do something like series['component_name'] to retrieve a univariate TimeSeries. But there is no way of indexing a stochastic series to retrieve one sample as a TimeSeries, right?

dennisbader commented 1 month ago

Ah sorry, you are right.

You would have to create a new series from the values. with series.with_values(), you can return a new series that has the same components and times as series, but with new values.

E.g.

new_series = series.with_values(series.values(sample=0))
dwolffram commented 1 month ago

Thanks, that was helpful!

However, I got the error ValueError: different number of dimensions on data and dims: 2 vs 3. After adding another dimension it works though:

new_series = series.with_values(np.expand_dims(series.values(sample=0), 1))
dennisbader commented 1 month ago

True 👍