Skip to main content

Time series forecasting suite using statistical models

Project description

statsforecast

Forecasting using statistical models

CI Python PyPi License

Install

pip install statsforecast

How to use

import numpy as np
import pandas as pd
from IPython.display import display, Markdown

from statsforecast import StatsForecast
from statsforecast.models import random_walk_with_drift, seasonal_naive, ses
def display_df(df):
    display(Markdown(df.to_markdown()))
rng = np.random.RandomState(0)
serie1 = np.arange(1, 8)[np.arange(100) % 7] + rng.randint(-1, 2, size=100)
serie2 = np.arange(100) + rng.rand(100)
series = pd.DataFrame(
    {
        'ds': pd.date_range('2000-01-01', periods=serie1.size + serie2.size, freq='D'),
        'y': np.hstack([serie1, serie2]),
    },
    index=pd.Index([0] * serie1.size + [1] * serie2.size, name='unique_id')
)
display_df(pd.concat([series.head(), series.tail()]))
unique_id ds y
0 2000-01-01 00:00:00 0
0 2000-01-02 00:00:00 2
0 2000-01-03 00:00:00 2
0 2000-01-04 00:00:00 4
0 2000-01-05 00:00:00 5
1 2000-07-14 00:00:00 95.7649
1 2000-07-15 00:00:00 96.9441
1 2000-07-16 00:00:00 97.75
1 2000-07-17 00:00:00 98.3394
1 2000-07-18 00:00:00 99.4895
fcst = StatsForecast(series, models=[random_walk_with_drift, (seasonal_naive, 7), (ses, 0.1)], freq='D', n_jobs=2)
forecasts = fcst.forecast(5)
display_df(forecasts)
2021-12-08 20:33:06 statsforecast.core INFO: Computing forecasts
2021-12-08 20:33:07 statsforecast.core INFO: Computed forecasts for random_walk_with_drift.
2021-12-08 20:33:07 statsforecast.core INFO: Computed forecasts for seasonal_naive_season_length-7.
2021-12-08 20:33:07 statsforecast.core INFO: Computed forecasts for ses_alpha-0.1.
unique_id ds random_walk_with_drift seasonal_naive_season_length-7 ses_alpha-0.1
0 2000-04-10 00:00:00 3.0303 3 3.85506
0 2000-04-11 00:00:00 3.06061 5 3.85506
0 2000-04-12 00:00:00 3.09091 4 3.85506
0 2000-04-13 00:00:00 3.12121 7 3.85506
0 2000-04-14 00:00:00 3.15152 6 3.85506
1 2000-07-19 00:00:00 100.489 93.0166 90.4709
1 2000-07-20 00:00:00 101.489 94.2307 90.4709
1 2000-07-21 00:00:00 102.489 95.7649 90.4709
1 2000-07-22 00:00:00 103.489 96.9441 90.4709
1 2000-07-23 00:00:00 104.489 97.75 90.4709

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

statsforecast-0.2.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

statsforecast-0.2.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file statsforecast-0.2.0.tar.gz.

File metadata

  • Download URL: statsforecast-0.2.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for statsforecast-0.2.0.tar.gz
Algorithm Hash digest
SHA256 45d51cbf895175b0860fc5fe79ad5524f12dd50e9959fc0c7354fd4f2d56b51a
MD5 33329344d1871c430479575b4c5310d1
BLAKE2b-256 6be885f261e125923a17a45772e1029de728c224541de270197697736f9227fd

See more details on using hashes here.

File details

Details for the file statsforecast-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: statsforecast-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.1 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for statsforecast-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9e4150083795a7d5c962162527bc9a140141cd3957b72c5fb21f27dbc065755
MD5 266f419fa9dd8a92b98aad6751167774
BLAKE2b-256 bc688f939502e6c22c2d302c8067cb6824c54c974ca484044aa2a892e2c4c6c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page