ProFeTorch
FB Prophet + Fastai + pyTorch.
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:
\begin{aligned} y &= b(T(t) + S(t) + F(x)|l,u) \ T(t) &= mt + a \ S(t) &= \sum_{n=1}^N\left(a_n \cos\left(\frac{2\pi nt}{P}\right) + b_n \sin\left(\frac{2\pi nt}{P}\right)\right) \ F(x) &= w^T x\ b(y|l,u) &= \begin{cases} l \quad \text{if } y < l \ y \quad \text{if } l < y < u \ u \quad \text{if } y > u \end{cases} \end{aligned}
where $T(t)$ is the trend line, $S(t)$ are the seasonal components composed of a fourier sum, $F(x)$ is a linear function which weights features that is not related to time.
The task is therefore to find the parameters $a, m, \cup_n a_n, \cup_n b_n, w$ that minimises a loss function $l(\hat{y}, y)$. The default is set to minimise $l1$ loss $\frac{1}{N}\sum_{i=1}^N |y_i - \hat{y_i}|$ 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: \begin{align} y_5 &= b(\hat{y} - (m_5 t + a_5)|l,u) \ y_{95} &= b(\hat{y} + (m_{95} t + a_{95})|l,u) \end{align}
Install
pip install profetorch
ProFeTorch Training
model_params = {'y_n':10, 'm_n':7, 'l':0, 'h': train_df['y'].max() * 2}
model = Model(train_df, model_args=model_params, epochs=30, alpha=1e-2, beta=0)
model.fit(train_df)
/opt/miniconda3/lib/python3.7/site-packages/pandas/core/frame.py:4117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
errors=errors,
Epoch 30/30 Training Loss: 0.3687, Validation Loss: 0.6105
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()
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.
Metadata
Release files for profetorch 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| profetorch-0.0.2.tar.gz | 11.2 kB | Without provenance | Details for profetorch-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| profetorch-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for profetorch-0.0.2-py3-none-any.whl |
Total release size: 27.1 kB
Release files / profetorch-0.0.2.tar.gz
| Download URL | profetorch-0.0.2.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd1b3221cd19dca98721cfd851912006897eebb94ee169b79124d03cbd263996
|
|
BLAKE2b-256 checksum How to use checksums |
a3e724c41365a656202655883559baa8e9e2b8c7914ce3618f719f5e6c6c6e11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Release files / profetorch-0.0.2-py3-none-any.whl
| Download URL | profetorch-0.0.2-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81f670db0ca9e997d2635afc3ad75bcb60275405fcb41679fa8bd7fdc22a4dd0
|
|
BLAKE2b-256 checksum How to use checksums |
be589f907bdf0bf604ba3e4938843b0d221adcd0204108612b63d6a9658974e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Security for profetorch 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.