Skip to main content

Time series forecasting suite using statistical models

Project description

statsforecast

Forecasting using statistical models

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')
forecasts = fcst.forecast(5)
display_df(forecasts)
2021-11-22 20:03:32 statsforecast.core INFO: Computing forecasts
2021-11-22 20:03:32 statsforecast.core INFO: Computed forecasts for random_walk_with_drift.
2021-11-22 20:03:33 statsforecast.core INFO: Computed forecasts for seasonal_naive_season_length-7.
2021-11-22 20:03:33 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.1.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statsforecast-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: statsforecast-0.1.0.tar.gz
  • Upload date:
  • Size: 13.0 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.1.0.tar.gz
Algorithm Hash digest
SHA256 e74b4f9bad476de1aa8ec0d59c03da0451be4407df30d8aea48354b12936c85c
MD5 fa7e7ddf2e33c2968fc39ec6e7bd0200
BLAKE2b-256 49ae6321796857b9c13234d9f247941965344a479319c9383ee9aa3047f43d31

See more details on using hashes here.

File details

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

File metadata

  • Download URL: statsforecast-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0338e108f96ad79fd82d78e54a5288e655c787dcc89a6e94400d8fc732991fd
MD5 9f566e4eebef36a771c0c51c7c169898
BLAKE2b-256 9b9ce9796d71623e48e340599b458bbc1061216ce44a6caf4f3d5a2d033894d2

See more details on using hashes here.

Supported by

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