The core.NeuralForecast class allows you to efficiently fit multiple NeuralForecast models for large sets of time series. It operates with pandas DataFrame df that identifies individual series and datestamps with the unique_id and ds columns, and the y column denotes the target time series variable. To assist development, we declare useful datasets that we use throughout all NeuralForecast’s unit tests.
Generates n_series of frequency freq of different lengths in the interval [min_length, max_length]. If n_temporal_features > 0, then each serie gets temporal features with random values. If n_static_features > 0, then a static dataframe is returned along the temporal dataframe. If equal_ends == True then all series end at the same date.
Parameters: n_series: int, number of series for synthetic panel. min_length: int, minimal length of synthetic panel’s series. max_length: int, minimal length of synthetic panel’s series. n_temporal_features: int, default=0, number of temporal exogenous variables for synthetic panel’s series. n_static_features: int, default=0, number of static exogenous variables for synthetic panel’s series. equal_ends: bool, if True, series finish in the same date stamp ds. freq: str, frequency of the data, panda’s available frequencies.
Returns: freq: pandas.DataFrame, synthetic panel with columns [unique_id, ds, y] and exogenous.
from neuralforecast.utils import generate_seriessynthetic_panel = generate_series(n_series=2)synthetic_panel.groupby('unique_id').head(4)
The classic Box & Jenkins airline data. Monthly totals of international airline passengers, 1949 to 1960.
It has been used as a reference on several forecasting libraries, since it is a series that shows clear trends and seasonalities it offers a nice opportunity to quickly showcase a model’s predictions performance.
from neuralforecast.utils import AirPassengersDFAirPassengersDF.head(12)
unique_id
ds
y
0
1.0
1949-01-31
112.0
1
1.0
1949-02-28
118.0
2
1.0
1949-03-31
132.0
3
1.0
1949-04-30
129.0
4
1.0
1949-05-31
121.0
5
1.0
1949-06-30
135.0
6
1.0
1949-07-31
148.0
7
1.0
1949-08-31
148.0
8
1.0
1949-09-30
136.0
9
1.0
1949-10-31
119.0
10
1.0
1949-11-30
104.0
11
1.0
1949-12-31
118.0
#We are going to plot the ARIMA predictions, and the prediction intervals.fig, ax = plt.subplots(1, 1, figsize = (20, 7))plot_df = AirPassengersDF.set_index('ds')plot_df[['y']].plot(ax=ax, linewidth=2)ax.set_title('AirPassengers Forecast', fontsize=22)ax.set_ylabel('Monthly Passengers', fontsize=20)ax.set_xlabel('Timestamp [t]', fontsize=20)ax.legend(prop={'size': 15})ax.grid()
import numpy as npimport pandas as pdn_static_features =3n_series =5static_features = np.random.uniform(low=0.0, high=1.0, size=(n_series, n_static_features))static_df = pd.DataFrame.from_records(static_features, columns = [f'static_{i}'for i inrange(n_static_features)])static_df['unique_id'] = np.arange(n_series)