Skip to main content

Data format

The required input format is a dataframe with at least the following columns:
  • unique_id with a unique identifier for each time serie
  • ds with the datestamp and a column
  • y with the values of theserie
Every other column is considered a static feature unless stated otherwise in TimeSeries.fit
For simplicity we’ll just take one time serie here.

TimeSeries

Utility class for storing and transforming time series data.

TimeSeries.fit_transform

Add the features to data and save the required information for the predictions step. If not all features are static, specify which ones are in static_features. If you don’t want to drop rows with null values after the transformations set dropna=False If keep_last_n is not None then that number of observations is kept across all series for updates. Parameters:

TimeSeries.predict

TimeSeries.update

Update the values of the stored series. Parameters:
The frequency is converted to an offset.
The date features are stored as they were passed to the constructor.
The transformations are stored as a dictionary where the key is the name of the transformation (name of the column in the dataframe with the computed features), which is built using build_transform_name and the value is a tuple where the first element is the lag it is applied to, then the function and then the function arguments.
Note that for lags we define the transformation as the identity function applied to its corresponding lag. This is because _transform_series takes the lag as an argument and shifts the array before computing the transformation.
The series values are stored as a GroupedArray in an attribute ga. If the data type of the series values is an int then it is converted to np.float32, this is because lags generate np.nans so we need a float data type for them.
The series ids are stored in an uids attribute.
For each time serie, the last observed date is stored so that predictions start from the last date + the frequency.
The last row of every serie without the y and ds columns are taken as static features.
If you pass static_features to TimeSeries.fit_transform then only these are kept.
You can also specify keep_last_n in TimeSeries.fit_transform, which means that after computing the features for training we want to keep only the last n samples of each time serie for computing the updates. This saves both memory and time, since the updates are performed by running the transformation functions on all time series again and keeping only the last value (the update). If you have very long time series and your updates only require a small sample it’s recommended that you set keep_last_n to the minimum number of samples required to compute the updates, which in this case is 15 since we have a rolling mean of size 14 over the lag 2 and in the first update the lag 2 becomes the lag 1. This is because in the first update the lag 1 is the last value of the series (or the lag 0), the lag 2 is the lag 1 and so on.
TimeSeries.fit_transform requires that the y column doesn’t have any null values. This is because the transformations could propagate them forward, so if you have null values in the y column you’ll get an error.
Once we have a trained model we can use TimeSeries.predict passing the model and the horizon to get the predictions back.
If we have dynamic features we can pass them to X_df.