pymc_forecast.datasets#
Dataset helpers for the examples and docs.
load_bart_od() downloads and caches the complete hourly BART
origin-destination panel. load_bart_weekly() and
load_bart_weekly_by_origin() derive compact weekly examples from that
source, load_victoria_electricity() and load_us_macro() read small
CSVs bundled with the package, and load_m5() downloads the M5 competition
files once and returns labeled sales and price panels. Every loader returns
labeled arrays; load_m5() adds the identifier, calendar, and weight tables.
- class pymc_forecast.datasets.M5Data(sales, price, keys, calendar, weights)[source]#
Bases:
NamedTupleM5 evaluation data: labeled sales and price panels plus three tables.
salesandpriceare float32xarray.DataArraypanels with dims("time", "series"): the"time"coord is the calendar date of each day and the"series"coord is the seriesid(item_idandstore_idjoined by_), in sales-file order.priceis the weekly shelf price repeated over the days ofwm_yr_wk, NaN where the item was not listed.keyshas one row per series with theidand the five hierarchy columns;calendarhas one row per day;weightsis the official evaluation weight table. Each field is available as an attribute of the same name, and the tuple unpacks in field order.- Parameters:
sales (
xarray.DataArray) – Float32 daily unit sales named"sales"with dims("time", "series"): training days followed by evaluation days, NaN on evaluation days for series missing from the test file.price (
xarray.DataArray) – Float32 daily shelf prices named"price"with the same dims and coords assales.keys (
pandas.DataFrame) – One row per series, in"series"order, with columnsid,item_id,dept_id,cat_id,store_idandstate_id.calendar (
pandas.DataFrame) – Thecalendar.csvtable (dateparsed as datetimes), one row per sales day.weights (
pandas.DataFrame) – Theweights_evaluation.csvtable, unchanged.
- sales#
Alias for field number 0
- price#
Alias for field number 1
- keys#
Alias for field number 2
- calendar#
Alias for field number 3
- weights#
Alias for field number 4
- pymc_forecast.datasets.load_bart_od()[source]#
Load complete hourly BART origin-destination ridership counts.
The four source shards are downloaded from the public Pyro dataset mirror, verified by SHA-256, and cached in the operating system’s user cache.
- Returns:
xarray.DataArray– Integer counts named"rides"with dims("time", "origin", "destination"). The time coordinate is hourlydatetime64values starting at the shards’ recorded start date (2011-01-01 for the current files), and station names label both origin and destination.
- pymc_forecast.datasets.load_bart_weekly()[source]#
Load total weekly BART ridership on the log scale.
The series is derived at load time from the complete public BART origin-destination dataset used by the Pyro and NumPyro forecasting examples. Hourly counts are summed over all origin-destination pairs, aggregated into non-overlapping 168-hour weeks starting at the first hour (a trailing partial week is dropped), and log-transformed.
- Returns:
xarray.DataArray– Log weekly totals named"log_rides"with dims("time",)and integer week coords0..n-1.
- pymc_forecast.datasets.load_bart_weekly_by_origin(num_series=8)[source]#
Load a weekly BART ridership panel grouped by origin station.
Counts are summed over destination stations and aggregated into non-overlapping 168-hour weeks (a trailing partial week is dropped) before applying
log1p. Aggregation happens a shard at a time, avoiding materializing the much larger full origin-destination panel. By default only the eight busiest origins are returned, which keeps hierarchical examples quick; passNonefor all stations.- Parameters:
num_series (
int, default8) – Number of busiest origin stations to retain, ordered busiest first (by total count);Nonekeeps all stations in source order.- Returns:
xarray.DataArray– Log weekly counts named"log_rides"with dims("time", "series"), integer week coords0..n-1on"time"and station names on the"series"coordinate.- Raises:
ValueError – If
num_seriesis less than 1.
- pymc_forecast.datasets.load_m5(cache_dir=None)[source]#
Load the M5 evaluation panel, downloading and caching the archive once.
The files come from Nixtla’s mirror of the competition data, pinned to commit
72b8e7fdand checked against a SHA-256 digest. The archive is about 50 MB and is downloaded and extracted intocache_dir, by defaultpooch.os_cache("pymc_forecast") / "m5"(~/.cache/pymc_forecast/m5on Linux,~/Library/Caches/pymc_forecast/m5on macOS); the archive is kept there next to the extracted files. When every competition file is already in that directory, nothing is downloaded. The two returned panels hold about 480 MB; parsing the CSVs peaks at about 2 GB.Series order follows
sales_train_evaluation.csv. The test file is aligned on the train keys, so a test-only row is ignored and a missing test row leaves NaN sales on the evaluation days. Weekly prices are mapped bywm_yr_wk; a calendar week absent fromsell_prices.csvis NaN and does not shift the other weeks.- Parameters:
cache_dir (
stroros.PathLike, optional) – Directory to download the archive into and extract it into (created if missing);Noneusespooch.os_cache("pymc_forecast") / "m5".- Returns:
M5Data– Labeled sales and price panels, identifiers, calendar, and official evaluation weights.- Raises:
ValueError – If a competition file lacks required columns or is inconsistent: duplicate item-store keys or series ids, overlapping or non-contiguous
d_*day columns, duplicate store-item-week prices, a calendar shorter than the sales, or duplicate calendar dates.
- pymc_forecast.datasets.load_us_macro()[source]#
Load quarterly US real GDP, consumption and investment levels.
The
statsmodelsmacrodatapanel (public domain; FRED, accessed December 2009), restricted to the three real-activity series: 1959Q1 to 2009Q3, seasonally adjusted annual rates in billions of chained 2005 US$. Bundled as a small CSV.- Returns:
xarray.DataArray– Levels with dims("time", "series");timeis a quarter-startDatetimeIndexandseriesis["realgdp", "realcons", "realinv"].
- pymc_forecast.datasets.load_victoria_electricity()[source]#
Load hourly Victoria (Australia) electricity demand and temperature.
The series covers the first eight weeks of 2014, sampled hourly — the Victoria electricity demand data used in the TensorFlow Probability structural-time-series case study and in Hyndman & Athanasopoulos’ Forecasting: Principles and Practice (original half-hourly data downsampled to hourly). Bundled as a small CSV.
- Returns:
demand (
xarray.DataArray) – Hourly electricity demand (GW), dims("time",)with an hourlyDatetimeIndexcoord.temperature (
xarray.DataArray) – Hourly temperature (°C), aligned withdemand.