BiTCN (Bidirectional Temporal Convolutional Network) is a parameter-efficient architecture designed for probabilistic forecasting. It uses a 'forward' network to encode future covariates and a 'backward' network to encode past observations and covariates. It is a lightweight alternative to RNNs (LSTM, GRU) and Transformers, requiring significantly fewer parameters and fewer hyperparameters to tune.
Key characteristics:
- Low Space Complexity: Requires orders of magnitude fewer parameters than Transformer-based methods.
- Efficiency: Computationally more efficient than common RNN methods.
- Hyperparameters: Typically requires tuning only two main hyperparameters.
import pandas as pd
import matplotlib.pyplot as plt
from neuralforecast import NeuralForecast
from neuralforecast.losses.pytorch import GMM
from neuralforecast.models import BiTCN
from neuralforecast.utils import AirPassengersPanel, AirPassengersStatic
Y_train_df = AirPassengersPanel[AirPassengersPanel.ds<AirPassengersPanel['ds'].values[-12]] # 132 train
Y_test_df = AirPassengersPanel[AirPassengersPanel.ds>=AirPassengersPanel['ds'].values[-12]].reset_index(drop=True) # 12 test
fcst = NeuralForecast(
models=[
BiTCN(h=12,
input_size=24,
loss=GMM(n_components=7, level=[80,90]),
max_steps=100,
scaler_type='standard',
futr_exog_list=['y_[lag12]'],
hist_exog_list=None,
stat_exog_list=['airline1'],
windows_batch_size=2048,
val_check_steps=10,
early_stop_patience_steps=-1,
),
],
freq='ME'
)
fcst.fit(df=Y_train_df, static_df=AirPassengersStatic)
forecasts = fcst.predict(futr_df=Y_test_df)
# Plot quantile predictions
Y_hat_df = forecasts.reset_index(drop=False).drop(columns=['unique_id','ds'])
plot_df = pd.concat([Y_test_df, Y_hat_df], axis=1)
plot_df = pd.concat([Y_train_df, plot_df])
plot_df = plot_df[plot_df.unique_id=='Airline1'].drop('unique_id', axis=1)
plt.plot(plot_df['ds'], plot_df['y'], c='black', label='True')
plt.plot(plot_df['ds'], plot_df['BiTCN-median'], c='blue', label='median')
plt.fill_between(x=plot_df['ds'][-12:],
y1=plot_df['BiTCN-lo-90'][-12:].values,
y2=plot_df['BiTCN-hi-90'][-12:].values,
alpha=0.4, label='level 90')
plt.legend()
plt.grid()