{"id":13526496,"url":"https://github.com/LongxingTan/Time-series-prediction","last_synced_at":"2025-04-01T07:32:43.416Z","repository":{"id":39722607,"uuid":"131993562","full_name":"LongxingTan/Time-series-prediction","owner":"LongxingTan","description":"tfts: Time Series Deep Learning Models in TensorFlow","archived":false,"fork":false,"pushed_at":"2025-03-15T03:16:16.000Z","size":3038,"stargazers_count":844,"open_issues_count":11,"forks_count":166,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-03-28T08:01:56.104Z","etag":null,"topics":["deep-learning","forecasting","keras-forecasting","keras-prediction","keras-time-series","machine-learning","neural-network","prediction","seq2seq","tensorflow","tf2","time-series","time-series-forecast","time-series-forecasting","timeseries","transformer","wavenet"],"latest_commit_sha":null,"homepage":"https://time-series-prediction.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LongxingTan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-03T12:43:20.000Z","updated_at":"2025-03-14T02:01:05.000Z","dependencies_parsed_at":"2023-02-10T13:30:39.667Z","dependency_job_id":"49c6344c-455d-403c-a8fd-0fcc551df327","html_url":"https://github.com/LongxingTan/Time-series-prediction","commit_stats":{"total_commits":45,"total_committers":3,"mean_commits":15.0,"dds":"0.11111111111111116","last_synced_commit":"f3db2337e08d0439abaf3997c44eb77d7d675963"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LongxingTan%2FTime-series-prediction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LongxingTan%2FTime-series-prediction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LongxingTan%2FTime-series-prediction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LongxingTan%2FTime-series-prediction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LongxingTan","download_url":"https://codeload.github.com/LongxingTan/Time-series-prediction/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246600848,"owners_count":20803495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","forecasting","keras-forecasting","keras-prediction","keras-time-series","machine-learning","neural-network","prediction","seq2seq","tensorflow","tf2","time-series","time-series-forecast","time-series-forecasting","timeseries","transformer","wavenet"],"created_at":"2024-08-01T06:01:30.636Z","updated_at":"2025-04-01T07:32:38.408Z","avatar_url":"https://github.com/LongxingTan.png","language":"Python","funding_links":[],"categories":["Code-Resource","⏳ Time Series Analysis"],"sub_categories":["2020","Tools"],"readme":"[license-image]: https://img.shields.io/badge/License-MIT-blue.svg\n[license-url]: https://opensource.org/licenses/MIT\n[pypi-image]: https://badge.fury.io/py/tfts.svg\n[pypi-url]: https://pypi.python.org/pypi/tfts\n[pepy-image]: https://pepy.tech/badge/tfts/month\n[pepy-url]: https://pepy.tech/project/tfts\n[build-image]: https://github.com/LongxingTan/Time-series-prediction/actions/workflows/test.yml/badge.svg?branch=master\n[build-url]: https://github.com/LongxingTan/Time-series-prediction/actions/workflows/test.yml?query=branch%3Amaster\n[lint-image]: https://github.com/LongxingTan/Time-series-prediction/actions/workflows/lint.yml/badge.svg?branch=master\n[lint-url]: https://github.com/LongxingTan/Time-series-prediction/actions/workflows/lint.yml?query=branch%3Amaster\n[docs-image]: https://readthedocs.org/projects/time-series-prediction/badge/?version=latest\n[docs-url]: https://time-series-prediction.readthedocs.io/en/latest/?version=latest\n[coverage-image]: https://codecov.io/gh/longxingtan/Time-series-prediction/branch/master/graph/badge.svg\n[coverage-url]: https://codecov.io/github/longxingtan/Time-series-prediction?branch=master\n[contributing-image]: https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat\n[contributing-url]: https://github.com/longxingtan/Time-series-prediction/blob/master/CONTRIBUTING.md\n[codeql-image]: https://github.com/longxingtan/Time-series-prediction/actions/workflows/codeql-analysis.yml/badge.svg\n[codeql-url]: https://github.com/longxingtan/Time-series-prediction/actions/workflows/codeql-analysis.yml\n\n\u003ch1 align=\"center\"\u003e\n\u003cimg src=\"./docs/source/_static/logo.svg\" width=\"400\" align=center/\u003e\n\u003c/h1\u003e\u003cbr\u003e\n\n[![LICENSE][license-image]][license-url]\n[![PyPI Version][pypi-image]][pypi-url]\n[![Build Status][build-image]][build-url]\n[![Lint Status][lint-image]][lint-url]\n[![Docs Status][docs-image]][docs-url]\n[![Code Coverage][coverage-image]][coverage-url]\n[![Contributing][contributing-image]][contributing-url]\n\n**[Documentation](https://time-series-prediction.readthedocs.io)** | **[Tutorials](https://time-series-prediction.readthedocs.io/en/latest/tutorials.html)** | **[Release Notes](https://time-series-prediction.readthedocs.io/en/latest/CHANGELOG.html)** | **[中文](https://github.com/LongxingTan/Time-series-prediction/blob/master/README_CN.md)**\n\n**TFTS** (TensorFlow Time Series) is an easy-to-use time series package, supporting the classical and latest deep learning methods in TensorFlow or Keras.\n- Support sota performance for time series task (prediction, classification, anomaly detection)\n- Provide advanced deep learning models for industry, research and competition\n- Documentation lives at [time-series-prediction.readthedocs.io](https://time-series-prediction.readthedocs.io)\n\n\n## Tutorial\n\n**Installation**\n\n- python \u003e= 3.7\n- tensorflow \u003e= 2.4\n\n```shell\npip install tfts\n```\n\n**Quick start**\n\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1LHdbrXmQGBSQuNTsbbM5-lAk5WENWF-Q?usp=sharing)\n[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://www.kaggle.com/code/tanlongxing/tensorflow-time-series-starter-tfts/notebook)\n\n```python\nimport matplotlib.pyplot as plt\nimport tfts\nfrom tfts import AutoModel, AutoConfig, KerasTrainer\n\ntrain_length = 24\npredict_length = 8\n(x_train, y_train), (x_valid, y_valid) = tfts.get_data(\"sine\", train_length, predict_length, test_size=0.2)\n\nmodel_name_or_path = 'seq2seq'\nconfig = AutoConfig.for_model(model_name_or_path)\nmodel = AutoModel.from_config(config, predict_length=predict_length)\ntrainer = KerasTrainer(model)\ntrainer.train((x_train, y_train), (x_valid, y_valid), n_epochs=3)\n\npred = trainer.predict(x_valid)\ntrainer.plot(history=x_valid, true=y_valid, pred=pred)\nplt.show()\n```\n\n**Prepare your own data**\n\nYou could train your own data by preparing 3D data as inputs, for both inputs and targets\n- option1 `np.ndarray`\n- option2 `tf.data.Dataset`\n\nEncoder only model inputs\n\n```python\nimport numpy as np\nfrom tfts import AutoConfig, AutoModel, KerasTrainer\n\ntrain_length = 49\npredict_length = 10\nn_feature = 2\n\nx_train = np.random.rand(1, train_length, n_feature)  # inputs: (batch, train_length, feature)\ny_train = np.random.rand(1, predict_length, 1)  # target: (batch, predict_length, 1)\nx_valid = np.random.rand(1, train_length, n_feature)\ny_valid = np.random.rand(1, predict_length, 1)\n\nconfig = AutoConfig.for_model('rnn')\nmodel = AutoModel.from_config(config, predict_length=predict_length)\ntrainer = KerasTrainer(model)\ntrainer.train(train_dataset=(x_train, y_train), valid_dataset=(x_valid, y_valid), n_epochs=1)\n```\n\nEncoder-decoder model inputs\n\n```python\n# option1: np.ndarray\nimport numpy as np\nfrom tfts import AutoConfig, AutoModel, KerasTrainer\n\ntrain_length = 49\npredict_length = 10\nn_encoder_feature = 2\nn_decoder_feature = 3\n\nx_train = (\n    np.random.rand(1, train_length, 1),  # inputs: (batch, train_length, 1)\n    np.random.rand(1, train_length, n_encoder_feature),  # encoder_feature: (batch, train_length, encoder_features)\n    np.random.rand(1, predict_length, n_decoder_feature),  # decoder_feature: (batch, predict_length, decoder_features)\n)\ny_train = np.random.rand(1, predict_length, 1)  # target: (batch, predict_length, 1)\n\nx_valid = (\n    np.random.rand(1, train_length, 1),\n    np.random.rand(1, train_length, n_encoder_feature),\n    np.random.rand(1, predict_length, n_decoder_feature),\n)\ny_valid = np.random.rand(1, predict_length, 1)\n\nconfig = AutoConfig.for_model(\"seq2seq\")\nmodel = AutoModel.from_config(config, predict_length=predict_length)\ntrainer = KerasTrainer(model)\ntrainer.train((x_train, y_train), (x_valid, y_valid), n_epochs=1)\n```\n\n```python\n# option2: tf.data.Dataset\nimport tensorflow as tf\nfrom tfts import AutoConfig, AutoModel, KerasTrainer\n\nclass FakeReader(object):\n    def __init__(self, predict_length):\n        train_length = 49\n        n_encoder_feature = 2\n        n_decoder_feature = 3\n        self.x = np.random.rand(15, train_length, 1)\n        self.encoder_feature = np.random.rand(15, train_length, n_encoder_feature)\n        self.decoder_feature = np.random.rand(15, predict_length, n_decoder_feature)\n        self.target = np.random.rand(15, predict_length, 1)\n\n    def __len__(self):\n        return len(self.x)\n\n    def __getitem__(self, idx):\n        return {\n            \"x\": self.x[idx],\n            \"encoder_feature\": self.encoder_feature[idx],\n            \"decoder_feature\": self.decoder_feature[idx],\n        }, self.target[idx]\n\n    def iter(self):\n        for i in range(len(self.x)):\n            yield self[i]\n\npredict_length = 10\ntrain_reader = FakeReader(predict_length=predict_length)\ntrain_loader = tf.data.Dataset.from_generator(\n    train_reader.iter,\n    ({\"x\": tf.float32, \"encoder_feature\": tf.float32, \"decoder_feature\": tf.float32}, tf.float32),\n)\ntrain_loader = train_loader.batch(batch_size=1)\nvalid_reader = FakeReader(predict_length=predict_length)\nvalid_loader = tf.data.Dataset.from_generator(\n    valid_reader.iter,\n    ({\"x\": tf.float32, \"encoder_feature\": tf.float32, \"decoder_feature\": tf.float32}, tf.float32),\n)\nvalid_loader = valid_loader.batch(batch_size=1)\n\nconfig = AutoConfig.for_model(\"seq2seq\")\nmodel = AutoModel.from_config(config, predict_length=predict_length)\ntrainer = KerasTrainer(model)\ntrainer.train(train_dataset=train_loader, valid_dataset=valid_loader, n_epochs=1)\n```\n\n**Prepare custom model config**\n\n```python\nimport tensorflow as tf\nimport tfts\nfrom tfts import AutoModel, AutoConfig\n\nconfig = AutoConfig.for_model('rnn')\nprint(config)\nconfig.rnn_hidden_size = 128\n\nmodel = AutoModel.from_config(config, predict_length=7, )\n```\n\n**Build your own model**\n\n\u003cdetails\u003e\u003csummary\u003e Full list of model tfts supported using AutoModel \u003c/summary\u003e\n\n- rnn\n- tcn\n- bert\n- nbeats\n- seq2seq\n- wavenet\n- transformer\n- informer\n\n\u003c/details\u003e\n\nYou could build the custom model based on tfts, especially\n- add custom-defined embeddings for categorical variables\n- add custom-defined head layers for classification or anomaly task\n\n```python\nimport tensorflow as tf\nfrom tensorflow.keras.layers import Input, Dense\nfrom tfts import AutoModel, AutoConfig\n\ndef build_model():\n    train_length = 24\n    train_features = 15\n    predict_length = 16\n\n    inputs = Input([train_length, train_features])\n    config = AutoConfig.for_model(\"seq2seq\")\n    backbone = AutoModel.from_config(config, predict_length=predict_length)\n    outputs = backbone(inputs)\n    outputs = Dense(1, activation=\"sigmoid\")(outputs)\n    model = tf.keras.Model(inputs=inputs, outputs=outputs)\n    model.compile(loss=\"mse\", optimizer=\"rmsprop\")\n    return model\n```\n\n\n## Examples\n\n- [TFTS-Bert](https://github.com/LongxingTan/KDDCup2022-Baidu) wins the **3rd place** in KDD Cup 2022-wind power forecasting\n- [TFTS-Seq2seq](https://github.com/LongxingTan/Data-competitions/tree/master/tianchi-enso-prediction) wins the **4th place** in Tianchi-ENSO prediction 2021\n\n\u003c!-- ### Performance\n\n[Time series prediction](./examples/run_prediction_simple.py) performance is evaluated by tfts implementation, not official\n\n| Performance | [web traffic\u003csup\u003emape\u003c/sup\u003e]() | [grocery sales\u003csup\u003ewrmse\u003c/sup\u003e](https://www.kaggle.com/competitions/favorita-grocery-sales-forecasting/data) | [m5 sales\u003csup\u003eval\u003c/sup\u003e]() | [ventilator\u003csup\u003eval\u003c/sup\u003e]() |\n| :-- | :-: | :-: | :-: | :-: |\n| [RNN]() | 672 | 47.7% |52.6% | 61.4% |\n| [DeepAR]() | 672 | 47.7% |52.6% | 61.4% |\n| [Seq2seq]() | 672 | 47.7% |52.6% | 61.4% |\n| [TCN]() | 672 | 47.7% |52.6% | 61.4% |\n| [WaveNet]() | 672 | 47.7% |52.6% | 61.4% |\n| [Bert]() | 672 | 47.7% |52.6% | 61.4% |\n| [Transformer]() | 672 | 47.7% |52.6% | 61.4% |\n| [Temporal-fusion-transformer]() | 672 | 47.7% |52.6% | 61.4% |\n| [Informer]() | 672 | 47.7% |52.6% | 61.4% |\n| [AutoFormer]() | 672 | 47.7% |52.6% | 61.4% |\n| [N-beats]() | 672 | 47.7% |52.6% | 61.4% |\n| [U-Net]() | 672 | 47.7% |52.6% | 61.4% |\n\n### More demos\n- [More complex prediction task](./notebooks)\n- [Time series classification](./examples/run_classification.py)\n- [Anomaly detection](./examples/run_anomaly.py)\n- [Uncertainty prediction](examples/run_uncertainty.py)\n- [Parameters tuning by optuna](examples/run_optuna_tune.py)\n- [Serving by tf-serving](./examples) --\u003e\n\nFor other DL frameworks, try [pytorch-forecasting](https://github.com/jdb78/pytorch-forecasting), [gluonts](https://github.com/awslabs/gluonts), [paddlets](https://github.com/PaddlePaddle/PaddleTS)\n\n\n## Citation\n\nIf you find tfts project useful in your research, please consider cite:\n\n```\n@misc{tfts2020,\n  author = {Longxing Tan},\n  title = {Time series prediction},\n  year = {2020},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://github.com/longxingtan/time-series-prediction}},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLongxingTan%2FTime-series-prediction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLongxingTan%2FTime-series-prediction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLongxingTan%2FTime-series-prediction/lists"}