This is an alternative implementation of prophet which uses quantile regression instead of MCMC sampling. It provides the following benefits over prophet:
- GPU usage.
- Strict(er) upper and lower bounds.
- Can add any other set of features to the time series.
The time series is implemented as follows:
where is the trend line, are the seasonal components composed of a fourier sum, is a linear function which weights features that is not related to time.
The task is therefore to find the parameters that minimises a loss function . The default is set to minimise loss so that the reliance on outliers is minimised. By default we also calculate the 5th and 95th quantile by minimising the tilted loss function. The quantile functions are calculated as:
Install¶
pip install profetorch
ProFeTorch Training¶
model_params = {'y_n':10, 'm_n':7, 'l':0, 'h': train_df['y'].max() * 2}
model = Model(model_args=model_params, epochs=30, alpha=1e-2)
model.fit(train_df)
y_pred = model.predict(df)
plt.figure(figsize=(12,5))
plt.scatter(df['ds'], df['y'], label='Data')
plt.plot(train_df['ds'], y_pred[:train_len,1], c='r', label='Train Set')
plt.fill_between(train_df['ds'], y_pred[:train_len,0], y_pred[:train_len,2], alpha=0.5)
plt.plot(test_df['ds'], y_pred[train_len:,1], c='g', label='Test Set')
plt.fill_between(test_df['ds'], y_pred[train_len:,0], y_pred[train_len:,2], alpha=0.5)
plt.show()
model.plot_components()
list(model.named_parameters())
Obviously more works needs to be done as seen in the graph above. However, note that:
- The seasonal component is captured.
- The quantiles are asymmetric, which cannot happen in the fb-prophet case.
- I will fix these short comings if there is enough interest.