https://github.com/sktime/pytorch-forecasting

Time series forecasting with PyTorch

https://github.com/sktime/pytorch-forecasting

Science Score: 46.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org, sciencedirect.com
  • Committers with academic emails
    3 of 80 committers (3.8%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.1%) to scientific vocabulary

Keywords

ai artifical-intelligense data-science deep-learning forecasting gpu machine-learning neural-networks pandas python pytorch pytorch-lightning temporal timeseries timeseries-forecasting uncertainty

Keywords from Contributors

data-mining distributed jax large-language-models sktime time-series-classification time-series-regression time-series-segmentation anomaly-detection changepoint-detection
Last synced: 5 months ago · JSON representation

Repository

Time series forecasting with PyTorch

Basic Info
Statistics
  • Stars: 4,468
  • Watchers: 43
  • Forks: 699
  • Open Issues: 585
  • Releases: 36
Topics
ai artifical-intelligense data-science deep-learning forecasting gpu machine-learning neural-networks pandas python pytorch pytorch-lightning temporal timeseries timeseries-forecasting uncertainty
Created over 5 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog License Codeowners

README.md

PyTorch Forecasting

PyTorch Forecasting is a PyTorch-based package for forecasting with state-of-the-art deep learning architectures. It provides a high-level API and uses PyTorch Lightning to scale training on GPU or CPU, with automatic logging.

| | Documentation · Tutorials · Release Notes | |---|---| | Open Source | MIT GC.OS Sponsored | | | Community | !discord !slack | | CI/CD | github-actions readthedocs platform Code Coverage | | Code | !pypi !conda !python-versions !black | | Downloads | PyPI - Downloads PyPI - Downloads Downloads |


Our article on Towards Data Science introduces the package and provides background information.

PyTorch Forecasting aims to ease state-of-the-art timeseries forecasting with neural networks for real-world cases and research alike. The goal is to provide a high-level API with maximum flexibility for professionals and reasonable defaults for beginners. Specifically, the package provides

  • A timeseries dataset class which abstracts handling variable transformations, missing values, randomized subsampling, multiple history lengths, etc.
  • A base model class which provides basic training of timeseries models along with logging in tensorboard and generic visualizations such actual vs predictions and dependency plots
  • Multiple neural network architectures for timeseries forecasting that have been enhanced for real-world deployment and come with in-built interpretation capabilities
  • Multi-horizon timeseries metrics
  • Hyperparameter tuning with optuna

The package is built on pytorch-lightning to allow training on CPUs, single and multiple GPUs out-of-the-box.

Installation

If you are working on windows, you need to first install PyTorch with

pip install torch -f https://download.pytorch.org/whl/torch_stable.html.

Otherwise, you can proceed with

pip install pytorch-forecasting

Alternatively, you can install the package via conda

conda install pytorch-forecasting pytorch -c pytorch>=1.7 -c conda-forge

PyTorch Forecasting is now installed from the conda-forge channel while PyTorch is install from the pytorch channel.

To use the MQF2 loss (multivariate quantile loss), also install pip install pytorch-forecasting[mqf2]

Documentation

Visit https://pytorch-forecasting.readthedocs.io to read the documentation with detailed tutorials.

Available models

The documentation provides a comparison of available models.

To implement new models or other custom components, see the How to implement new models tutorial. It covers basic as well as advanced architectures.

Usage example

Networks can be trained with the PyTorch Lighning Trainer on pandas Dataframes which are first converted to a TimeSeriesDataSet.

```python

imports for training

import lightning.pytorch as pl from lightning.pytorch.loggers import TensorBoardLogger from lightning.pytorch.callbacks import EarlyStopping, LearningRateMonitor

import dataset, network to train and metric to optimize

from pytorch_forecasting import TimeSeriesDataSet, TemporalFusionTransformer, QuantileLoss from lightning.pytorch.tuner import Tuner

load data: this is pandas dataframe with at least a column for

* the target (what you want to predict)

* the timeseries ID (which should be a unique string to identify each timeseries)

* the time of the observation (which should be a monotonically increasing integer)

data = ...

define the dataset, i.e. add metadata to pandas dataframe for the model to understand it

maxencoderlength = 36 maxpredictionlength = 6 training_cutoff = "YYYY-MM-DD" # day for cutoff

training = TimeSeriesDataSet( data[lambda x: x.date <= trainingcutoff], timeidx= ..., # column name of time of observation target= ..., # column name of target to predict groupids=[ ... ], # column name(s) for timeseries IDs maxencoderlength=maxencoderlength, # how much history to use maxpredictionlength=maxpredictionlength, # how far to predict into future # covariates static for a timeseries ID staticcategoricals=[ ... ], staticreals=[ ... ], # covariates known and unknown in the future to inform prediction timevaryingknowncategoricals=[ ... ], timevaryingknownreals=[ ... ], timevaryingunknowncategoricals=[ ... ], timevaryingunknown_reals=[ ... ], )

create validation dataset using the same normalization techniques as for the training dataset

validation = TimeSeriesDataSet.fromdataset(training, data, minpredictionidx=training.index.time.max() + 1, stoprandomization=True)

convert datasets to dataloaders for training

batchsize = 128 traindataloader = training.todataloader(train=True, batchsize=batchsize, numworkers=2) valdataloader = validation.todataloader(train=False, batchsize=batchsize, num_workers=2)

create PyTorch Lighning Trainer with early stopping

earlystopcallback = EarlyStopping(monitor="valloss", mindelta=1e-4, patience=1, verbose=False, mode="min") lrlogger = LearningRateMonitor() trainer = pl.Trainer( maxepochs=100, accelerator="auto", # run on CPU, if on multiple GPUs, use strategy="ddp" gradientclipval=0.1, limittrainbatches=30, # 30 batches per epoch callbacks=[lrlogger, earlystopcallback], logger=TensorBoardLogger("lightninglogs") )

define network to train - the architecture is mostly inferred from the dataset, so that only a few hyperparameters have to be set by the user

tft = TemporalFusionTransformer.fromdataset( # dataset training, # architecture hyperparameters hiddensize=32, attentionheadsize=1, dropout=0.1, hiddencontinuoussize=16, # loss metric to optimize loss=QuantileLoss(), # logging frequency loginterval=2, # optimizer parameters learningrate=0.03, reduceonplateau_patience=4 ) print(f"Number of parameters in network: {tft.size()/1e3:.1f}k")

find the optimal learning rate

res = Tuner(trainer).lrfind( tft, traindataloaders=traindataloader, valdataloaders=valdataloader, earlystopthreshold=1000.0, maxlr=0.3, )

and plot the result - always visually confirm that the suggested learning rate makes sense

print(f"suggested learning rate: {res.suggestion()}") fig = res.plot(show=True, suggest=True) fig.show()

fit the model on the data - redefine the model with the correct learning rate if necessary

trainer.fit( tft, traindataloaders=traindataloader, valdataloaders=valdataloader, ) ```

Owner

  • Name: sktime
  • Login: sktime
  • Kind: organization
  • Email: sktime.toolbox@gmail.com

A unified framework for machine learning with time series

Committers

Last synced: 6 months ago

All Time
  • Total Commits: 1,368
  • Total Committers: 80
  • Avg Commits per committer: 17.1
  • Development Distribution Score (DDS): 0.576
Past Year
  • Commits: 130
  • Committers: 35
  • Avg Commits per committer: 3.714
  • Development Distribution Score (DDS): 0.669
Top Committers
Name Email Commits
Jan Beitner b****n@b****m 580
dependabot[bot] 4****]@u****m 354
dependabot-preview[bot] 2****]@u****m 115
Franz Király f****y@u****k 54
Franz Király f****y@g****i 43
dehoyosb d****2@g****m 27
Jan Beitner j****r@i****m 25
Felix Hirwa Nshuti h****x@g****m 15
Jake F j****f@b****m 13
Aryan Saini 1****x@u****m 10
Pranav Bhat 6****P@u****m 10
Xinyu-Wu-0000 x****u@o****m 8
Daniil Gafni d****i@i****u 7
Jan Beitner j****r@g****m 5
Jirka Borovec 6****a@u****m 4
Li Yu l****8@g****m 4
Luke Merrick l****k@m****i 4
Xinyu Wu 5****u@u****m 4
Ben Steel b****l@g****m 3
Jirka j****c@s****z 3
Julio Antonio Soto j****o@e****s 3
sirius a****s@g****m 3
Anirban Ray 3****a@u****m 2
Christy Bergman c****n@g****m 2
Elias Nehme e****2@g****m 2
Ewan Thompson e****t@g****m 2
JustinNeumann J****n@u****m 2
NISHANT KUMAR a****7@g****m 2
Oleg p****o@g****m 2
Timo Klerx t****k@m****e 2
and 50 more...

Issues and Pull Requests

Last synced: 5 months ago

All Time
  • Total issues: 166
  • Total pull requests: 280
  • Average time to close issues: 9 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 85
  • Total pull request authors: 40
  • Average comments per issue: 1.81
  • Average comments per pull request: 3.45
  • Merged pull requests: 170
  • Bot issues: 0
  • Bot pull requests: 21
Past Year
  • Issues: 134
  • Pull requests: 225
  • Average time to close issues: 22 days
  • Average time to close pull requests: 14 days
  • Issue authors: 53
  • Pull request authors: 24
  • Average comments per issue: 0.9
  • Average comments per pull request: 3.68
  • Merged pull requests: 136
  • Bot issues: 0
  • Bot pull requests: 16
Top Authors
Issue Authors
  • fkiraly (31)
  • PranavBhatP (18)
  • phoeenniixx (9)
  • jobs-git (8)
  • cngmid (5)
  • arizzuto (3)
  • Neronjust2017 (3)
  • workhours (3)
  • moghadas76 (3)
  • benHeid (3)
  • hagersalehahmed (2)
  • mrgreen3325 (2)
  • JeremyKulcsarDS (2)
  • mkuiack (2)
  • grudloff (2)
Pull Request Authors
  • fkiraly (111)
  • phoeenniixx (28)
  • PranavBhatP (24)
  • dependabot[bot] (21)
  • fnhirwa (20)
  • Borda (7)
  • RUPESH-KUMAR01 (6)
  • jobs-git (4)
  • Vishnu-Rangiah (4)
  • cngmid (4)
  • julian-fong (4)
  • XinyuWuu (4)
  • yarnabrina (3)
  • ewth (3)
  • jdb78 (3)
Top Labels
Issue Labels
bug (56) enhancement (46) documentation (13) maintenance (8) API design (6) module:models (4) question (3) feature request (3) good first issue (3) module:test_framework (2) dependencies (1) new network (1) module:metrics (1)
Pull Request Labels
maintenance (95) enhancement (45) documentation (22) dependencies (18) bug (18) release (13) module:models (7) API design (6) module:test_framework (6) new network (4) module:metrics (2)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 259,879 last-month
  • Total docker downloads: 127
  • Total dependent packages: 9
    (may contain duplicates)
  • Total dependent repositories: 34
    (may contain duplicates)
  • Total versions: 75
  • Total maintainers: 2
pypi.org: pytorch-forecasting

Forecasting timeseries with PyTorch - dataloaders, normalizers, metrics and models

  • Versions: 39
  • Dependent Packages: 9
  • Dependent Repositories: 34
  • Downloads: 259,879 Last month
  • Docker Downloads: 127
Rankings
Dependent packages count: 0.8%
Downloads: 1.2%
Stargazers count: 1.3%
Average: 1.8%
Forks count: 2.3%
Dependent repos count: 2.5%
Docker downloads count: 2.8%
Maintainers (2)
Last synced: 6 months ago
proxy.golang.org: github.com/sktime/pytorch-forecasting
  • Versions: 36
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 6 months ago

Dependencies

.github/workflows/autoapprove.yml actions
  • dependabot/fetch-metadata v1.1.1 composite
.github/workflows/automerge.yml actions
  • dependabot/fetch-metadata v1.1.1 composite
.github/workflows/lint.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/pypi_release.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/test.yml actions
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • actions/setup-python v1 composite
  • actions/upload-artifact v2 composite
  • codecov/codecov-action v1 composite
docs/requirements.txt pypi
  • cloudpickle *
  • docutils *
  • fastapi >0.80
  • ipython *
  • lightning >=2.0.0
  • matplotlib *
  • nbconvert >=6.3.0
  • nbsphinx *
  • optuna >=3.1.0
  • pandas >=1.3
  • pandoc *
  • pydata-sphinx-theme *
  • pytorch-optimizer >=2.5.1
  • recommonmark >=0.7.1
  • scikit-learn >1.2
  • scipy *
  • sphinx >3.2
  • statsmodels *
  • torch >=2.0,
poetry.lock pypi
  • 215 dependencies
pyproject.toml pypi
  • cpflows ^0.1.2
  • fastapi >=0.80
  • lightning ^2.0.0
  • matplotlib *
  • networkx ^3.0.0
  • optuna ^3.1.0
  • pandas >=1.3.0,<=3.0.0
  • pytest-github-actions-annotate-failures *
  • python >=3.8,<3.11
  • pytorch-optimizer ^2.5.1
  • scikit-learn ^1.2
  • scipy ^1.8
  • statsmodels *
  • torch ^2.0.0,!=2.0.1