Skip to content

Pytorch forecasting

polars_ts.adapters.pytorch_forecasting

Adapter for pytorch-forecasting (TFT, DeepAR, etc.).

to_pytorch_forecasting(df, target_col='y', id_col='unique_id', time_col='ds', time_idx_col='time_idx')

Convert a polars-ts DataFrame to pytorch-forecasting format.

Returns a dict with "data" (a pandas DataFrame) and "metadata" needed to construct a TimeSeriesDataSet.

pytorch-forecasting requires a pandas DataFrame with a numeric time index column.

from_pytorch_forecasting(predictions, id_col='unique_id', time_col='ds')

Convert pytorch-forecasting predictions back to polars-ts format.

Parameters

predictions A pandas DataFrame or numpy array of predictions. If a DataFrame, it should have id/time columns plus prediction values. If a numpy array, a simple DataFrame is returned.