https://github.com/sktime/pytorch-forecasting
Time series forecasting with PyTorch
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
Keywords from Contributors
Repository
Time series forecasting with PyTorch
Basic Info
- Host: GitHub
- Owner: sktime
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://pytorch-forecasting.readthedocs.io/
- Size: 40.7 MB
Statistics
- Stars: 4,468
- Watchers: 43
- Forks: 699
- Open Issues: 585
- Releases: 36
Topics
Metadata Files
README.md
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 |
| |
| Community |
|
| CI/CD |
|
| Code |
|
| 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.
- Temporal Fusion Transformers for Interpretable Multi-horizon Time Series Forecasting which outperforms DeepAR by Amazon by 36-69% in benchmarks
- N-BEATS: Neural basis expansion analysis for interpretable time series forecasting which has (if used as ensemble) outperformed all other methods including ensembles of traditional statical methods in the M4 competition. The M4 competition is arguably the most important benchmark for univariate time series forecasting.
- N-HiTS: Neural Hierarchical Interpolation for Time Series Forecasting which supports covariates and has consistently beaten N-BEATS. It is also particularly well-suited for long-horizon forecasting.
- DeepAR: Probabilistic forecasting with autoregressive recurrent networks which is the one of the most popular forecasting algorithms and is often used as a baseline
- Simple standard networks for baselining: LSTM and GRU networks as well as a MLP on the decoder
- A baseline model that always predicts the latest known value
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
- Website: https://www.sktime.net
- Repositories: 29
- Profile: https://github.com/sktime
A unified framework for machine learning with time series
Committers
Last synced: 6 months ago
Top Committers
| Name | 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... | ||
Committer Domains (Top 20 + Academic)
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
Pull Request Labels
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
- Documentation: https://pytorch-forecasting.readthedocs.io/
- License: MIT License
-
Latest release: 1.4.0
published 8 months ago
Rankings
proxy.golang.org: github.com/sktime/pytorch-forecasting
- Documentation: https://pkg.go.dev/github.com/sktime/pytorch-forecasting#section-documentation
- License: mit
-
Latest release: v1.4.0
published 8 months ago
Rankings
Dependencies
- dependabot/fetch-metadata v1.1.1 composite
- dependabot/fetch-metadata v1.1.1 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
- 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
- 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,
- 215 dependencies
- 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