{"id":13958506,"url":"https://github.com/EvilPsyCHo/Deep-Time-Series-Prediction","last_synced_at":"2025-07-21T00:31:01.698Z","repository":{"id":40201887,"uuid":"216497547","full_name":"EvilPsyCHo/Deep-Time-Series-Prediction","owner":"EvilPsyCHo","description":"Seq2Seq, Bert, Transformer, WaveNet for time series prediction.","archived":false,"fork":false,"pushed_at":"2024-07-25T10:58:23.000Z","size":4761,"stargazers_count":578,"open_issues_count":10,"forks_count":79,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-11-22T15:02:22.914Z","etag":null,"topics":["attention","bert","deep-learning","kaggle","lstm","pytorch","regression","seq2seq","series-prediction","time-series-forecasting","toturial","wavenet"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EvilPsyCHo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-10-21T06:53:07.000Z","updated_at":"2024-11-21T07:43:49.000Z","dependencies_parsed_at":"2024-11-15T14:00:42.664Z","dependency_job_id":"7da639e7-b7d0-4252-b68d-c238980a12ac","html_url":"https://github.com/EvilPsyCHo/Deep-Time-Series-Prediction","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvilPsyCHo%2FDeep-Time-Series-Prediction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvilPsyCHo%2FDeep-Time-Series-Prediction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvilPsyCHo%2FDeep-Time-Series-Prediction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EvilPsyCHo%2FDeep-Time-Series-Prediction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EvilPsyCHo","download_url":"https://codeload.github.com/EvilPsyCHo/Deep-Time-Series-Prediction/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226850011,"owners_count":17691897,"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":["attention","bert","deep-learning","kaggle","lstm","pytorch","regression","seq2seq","series-prediction","time-series-forecasting","toturial","wavenet"],"created_at":"2024-08-08T13:01:40.572Z","updated_at":"2024-11-28T02:30:51.475Z","avatar_url":"https://github.com/EvilPsyCHo.png","language":"Python","funding_links":[],"categories":["时间序列","Awesome Code"],"sub_categories":["网络服务_其他","arXiv"],"readme":"# DeepSeries\nDeep Learning Models for time series prediction.\n\n## Models\n\n- [x] Seq2Seq / Attention\n- [x] WaveNet\n- [ ] Bert / Transformer\n\n## Quick Start\n\n```python\nfrom deepseries.models import Wave2Wave, RNN2RNN\nfrom deepseries.train import Learner\nfrom deepseries.data import Value, create_seq2seq_data_loader, forward_split\nfrom deepseries.nn import RMSE, MSE\nimport deepseries.functional as F\nimport numpy as np\nimport torch\n\nbatch_size = 16\nenc_len = 36\ndec_len = 12\nseries_len = 1000\n\nepoch = 100\nlr = 0.001\n\nvalid_size = 12\ntest_size = 12\n\nseries = np.sin(np.arange(0, series_len)) + np.random.normal(0, 0.1, series_len) + np.log2(np.arange(1, series_len+1))\nseries = series.reshape(1, 1, -1)\n\ntrain_idx, valid_idx = forward_split(np.arange(series_len), enc_len=enc_len, valid_size=valid_size+test_size)\nvalid_idx, test_idx = forward_split(valid_idx, enc_len, test_size)\n\n# mask test, will not be used for calculating mean/std.\nmask = np.zeros_like(series).astype(bool)\nmask[:, :, test_idx] = False\nseries, mu, std = F.normalize(series, axis=2, fillna=True, mask=mask)\n\n# create train/valid dataset\ntrain_dl = create_seq2seq_data_loader(series[:, :, train_idx], enc_len, dec_len, sampling_rate=0.1,\n                                      batch_size=batch_size, seq_last=True, device='cuda')\nvalid_dl = create_seq2seq_data_loader(series[:, :, valid_idx], enc_len, dec_len,\n                                      batch_size=batch_size, seq_last=True, device='cuda')\n\n# define model\nwave = Wave2Wave(target_size=1, num_layers=6, num_blocks=1, dropout=0.1, loss_fn=RMSE())\nwave.cuda()\nopt = torch.optim.Adam(wave.parameters(), lr=lr)\n\n# train model\nwave_learner = Learner(wave, opt, root_dir=\"./wave\", )\nwave_learner.fit(max_epochs=epoch, train_dl=train_dl, valid_dl=valid_dl, early_stopping=True, patient=16)\n\n# load best model\nwave_learner.load(wave_learner.best_epoch)\n\n# predict and show result\nimport matplotlib.pyplot as plt\nwave_preds = wave_learner.model.predict(torch.tensor(series[:, :, test_idx[:-12]]).float().cuda(), 12).cpu().numpy().reshape(-1)\n\nplt.plot(series[:, :, -48:-12].reshape(-1))\nplt.plot(np.arange(36, 48), wave_preds, label=\"wave2wave preds\")\nplt.plot(np.arange(36, 48), series[:, :, test_idx[-12:]].reshape(-1), label=\"target\")\nplt.legend()\n```\n\n![](assets/wave_sin_log_curve_prediction.png)\n\n\n\n**More examples will be update in example folder soon.**\n\n\n\n## Performence\n\n\n\nI will test model performence in Kaggle or other data science competition. It will comming soon.\n\n\n\n## Install\n\n```shell\ngit clone https://github.com/EvilPsyCHo/Deep-Time-Series-Prediction.git\ncd Deep-Time-Series-Prediction\npython setup.py install\n```\n\n\n\n## Refs\n\n- [WaveNet Keras Toturial: TimeSeries_Seq2Seq](https://github.com/JEddy92/TimeSeries_Seq2Seq)\n- [WaveNet Kaggle Web Traffic Forcasting Competition RANK 6](https://github.com/sjvasquez/web-traffic-forecasting)\n- [Seq2Seq Kaggle Web Traffic Forcasting Competition RANK 1](https://www.kaggle.com/c/web-traffic-time-series-forecasting/discussion/43795#latest-631996)\n- [Kaggle: Corporación Favorita Grocery Sales Forecasting Top1 LSTM/LGBM](https://www.kaggle.com/c/favorita-grocery-sales-forecasting/discussion/47582)\n- [Kaggle: Corporación Favorita Grocery Sales Forecasting Top5 LGBM/CNN/Seq2Seq](https://www.kaggle.com/c/favorita-grocery-sales-forecasting/discussion/47556)\n- [Temporal Pattern Attention for Multivariate Time Series Forecasting, 2018](https://arxiv.org/abs/1809.04206)\n- BahdanauAttention: NEURAL MACHINE TRANSLATION BY JOINTLY LEARNING TO ALIGN AND TRANSLATE\n- Effective Approaches to Attention-based Neural Machine Translation\n- BahdanauAttention and LuongAttention","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEvilPsyCHo%2FDeep-Time-Series-Prediction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEvilPsyCHo%2FDeep-Time-Series-Prediction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEvilPsyCHo%2FDeep-Time-Series-Prediction/lists"}