Forecasting utilities
Project description
Install
PyPI
pip install utilsforecast
Conda
conda install -c conda-forge utilsforecast
How to use
Generate synthetic data
from utilsforecast.data import generate_series
series = generate_series(3, with_trend=True, static_as_categorical=False)
series
| | unique_id | ds | y |
|-----|-----------|------------|------------|
| 0 | 0 | 2000-01-01 | 0.422133 |
| 1 | 0 | 2000-01-02 | 1.501407 |
| 2 | 0 | 2000-01-03 | 2.568495 |
| 3 | 0 | 2000-01-04 | 3.529085 |
| 4 | 0 | 2000-01-05 | 4.481929 |
| ... | ... | ... | ... |
| 481 | 2 | 2000-06-11 | 163.914625 |
| 482 | 2 | 2000-06-12 | 166.018479 |
| 483 | 2 | 2000-06-13 | 160.839176 |
| 484 | 2 | 2000-06-14 | 162.679603 |
| 485 | 2 | 2000-06-15 | 165.089288 |
Plotting
from utilsforecast.plotting import plot_series
fig = plot_series(series, plot_random=False, max_insample_length=50, engine='matplotlib')
fig.savefig('imgs/index.png', bbox_inches='tight')
Preprocessing
from utilsforecast.preprocessing import fill_gaps
serie = series[series['unique_id'].eq(0)].tail(10)
# drop some points
with_gaps = serie.sample(frac=0.5, random_state=0).sort_values('ds')
with_gaps
Example output with missing dates:
| | unique_id | ds | y |
|-----|-----------|------------|-----------|
| 213 | 0 | 2000-08-01 | 18.543147 |
| 214 | 0 | 2000-08-02 | 19.941764 |
| 216 | 0 | 2000-08-04 | 21.968733 |
| 220 | 0 | 2000-08-08 | 19.091509 |
| 221 | 0 | 2000-08-09 | 20.220739 |
fill_gaps(with_gaps, freq='D')
Returns:
| | unique_id | ds | y |
|-----|-----------|------------|-----------|
| 0 | 0 | 2000-08-01 | 18.543147 |
| 1 | 0 | 2000-08-02 | 19.941764 |
| 2 | 0 | 2000-08-03 | NaN |
| 3 | 0 | 2000-08-04 | 21.968733 |
| 4 | 0 | 2000-08-05 | NaN |
| 5 | 0 | 2000-08-06 | NaN |
| 6 | 0 | 2000-08-07 | NaN |
| 7 | 0 | 2000-08-08 | 19.091509 |
| 8 | 0 | 2000-08-09 | 20.220739 |
Evaluating
from functools import partial
import numpy as np
from utilsforecast.evaluation import evaluate
from utilsforecast.losses import mape, mase
valid = series.groupby('unique_id').tail(7).copy()
train = series.drop(valid.index)
rng = np.random.RandomState(0)
valid['seas_naive'] = train.groupby('unique_id')['y'].tail(7).values
valid['rand_model'] = valid['y'] * rng.rand(valid['y'].shape[0])
daily_mase = partial(mase, seasonality=7)
evaluate(valid, metrics=[mape, daily_mase], train_df=train)
| | unique_id | metric | seas_naive | rand_model |
|-----|-----------|--------|------------|------------|
| 0 | 0 | mape | 0.024139 | 0.440173 |
| 1 | 1 | mape | 0.054259 | 0.278123 |
| 2 | 2 | mape | 0.042642 | 0.480316 |
| 3 | 0 | mase | 0.907149 | 16.418014 |
| 4 | 1 | mase | 0.991635 | 6.404254 |
| 5 | 2 | mase | 1.013596 | 11.365040 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file utilsforecast-0.2.15.tar.gz.
File metadata
- Download URL: utilsforecast-0.2.15.tar.gz
- Upload date:
- Size: 60.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c36d65d698a88d0fadc93d2d6737c304c3776397c60ae551ee17aa678caf3659
|
|
| MD5 |
30410db1aab4868882814334fbe593b3
|
|
| BLAKE2b-256 |
d9558a37bb9ce36541fd353466259a07ccfdfaf25c996f3a71d989af4d4c7ba4
|
Provenance
The following attestation bundles were made for utilsforecast-0.2.15.tar.gz:
Publisher:
release.yml on Nixtla/utilsforecast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
utilsforecast-0.2.15.tar.gz -
Subject digest:
c36d65d698a88d0fadc93d2d6737c304c3776397c60ae551ee17aa678caf3659 - Sigstore transparency entry: 738192803
- Sigstore integration time:
-
Permalink:
Nixtla/utilsforecast@1d4f57f4390fa5a3f594f5bf5579322ed083d616 -
Branch / Tag:
refs/tags/v0.2.15 - Owner: https://github.com/Nixtla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1d4f57f4390fa5a3f594f5bf5579322ed083d616 -
Trigger Event:
push
-
Statement type:
File details
Details for the file utilsforecast-0.2.15-py3-none-any.whl.
File metadata
- Download URL: utilsforecast-0.2.15-py3-none-any.whl
- Upload date:
- Size: 40.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b43bf5107e3cba13604cd86e93b5cf4906b57105b1900ccf98b8978aabd4150
|
|
| MD5 |
66d95fdbe63c9fea784aa148cd1591e8
|
|
| BLAKE2b-256 |
6f116c6ee61958b8e60f634b39e2f9a004f5d1c479cb962a2001fc3c72ceed78
|
Provenance
The following attestation bundles were made for utilsforecast-0.2.15-py3-none-any.whl:
Publisher:
release.yml on Nixtla/utilsforecast
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
utilsforecast-0.2.15-py3-none-any.whl -
Subject digest:
4b43bf5107e3cba13604cd86e93b5cf4906b57105b1900ccf98b8978aabd4150 - Sigstore transparency entry: 738192806
- Sigstore integration time:
-
Permalink:
Nixtla/utilsforecast@1d4f57f4390fa5a3f594f5bf5579322ed083d616 -
Branch / Tag:
refs/tags/v0.2.15 - Owner: https://github.com/Nixtla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1d4f57f4390fa5a3f594f5bf5579322ed083d616 -
Trigger Event:
push
-
Statement type: