├── .idea ├── LSTM-Load-Forecasting.iml ├── dictionaries │ ├── Administrator.xml │ └── KI.xml ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── other.xml ├── vcs.xml └── workspace.xml ├── LICENSE ├── LSTMs ├── multivariate_multi_step.py ├── multivariate_single_step.py └── univariate_single_step.py ├── README.md ├── __pycache__ ├── args.cpython-37.pyc ├── data_process.cpython-37.pyc ├── models.cpython-37.pyc └── util.cpython-37.pyc ├── data └── data.csv ├── models ├── multivariate_multi_step.pkl ├── multivariate_single_step.pkl └── univariate_single_step.pkl └── tree.txt /.idea/LSTM-Load-Forecasting.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /.idea/dictionaries/Administrator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | mape 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/dictionaries/KI.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | anqiudata 5 | pythonhashseed 6 | univariate 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/other.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 18 | 19 | 20 | 22 | 23 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 71 | 72 | 73 | 93 | 94 | 95 | 115 | 116 | 117 | 137 | 138 | 139 | 159 | 160 | 161 | 181 | 182 | 183 | 203 | 204 | 205 | 225 | 226 | 227 | 247 | 248 | 249 | 269 | 270 | 271 | 291 | 292 | 293 | 313 | 314 | 315 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 1646136315444 361 | 420 | 421 | 422 | 423 | 425 | 426 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 KI 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LSTMs/multivariate_multi_step.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | """ 3 | @Time:2022/04/04 23:10 4 | @Author:KI 5 | @File:multivariate_multi_step.py 6 | @Motto:Hungry And Humble 7 | """ 8 | import os 9 | import sys 10 | 11 | curPath = os.path.abspath(os.path.dirname(__file__)) 12 | rootPath = os.path.split(curPath)[0] 13 | sys.path.append(rootPath) 14 | 15 | from args import mm_args_parser 16 | from util import train, test, load_data 17 | 18 | path = os.path.abspath(os.path.dirname(os.getcwd())) 19 | LSTM_PATH = path + '/models/multivariate_multi_step.pkl' 20 | 21 | 22 | if __name__ == '__main__': 23 | args = mm_args_parser() 24 | flag = 'mm' 25 | Dtr, Val, Dte, m, n = load_data(args, flag) 26 | train(args, Dtr, Val, LSTM_PATH) 27 | test(args, Dte, LSTM_PATH, m, n) 28 | -------------------------------------------------------------------------------- /LSTMs/multivariate_single_step.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @Time : 2022/1/18 14:27 4 | @Author :KI 5 | @File :multivariate_single_step.py 6 | @Motto:Hungry And Humble 7 | 8 | """ 9 | import os 10 | import sys 11 | 12 | curPath = os.path.abspath(os.path.dirname(__file__)) 13 | rootPath = os.path.split(curPath)[0] 14 | sys.path.append(rootPath) 15 | 16 | from args import ms_args_parser 17 | from util import train, test, load_data 18 | 19 | path = os.path.abspath(os.path.dirname(os.getcwd())) 20 | LSTM_PATH = path + '/models/multivariate_single_step.pkl' 21 | 22 | 23 | if __name__ == '__main__': 24 | args = ms_args_parser() 25 | flag = 'ms' 26 | Dtr, Val, Dte, m, n = load_data(args, flag) 27 | train(args, Dtr, Val, LSTM_PATH) 28 | test(args, Dte, LSTM_PATH, m, n) 29 | -------------------------------------------------------------------------------- /LSTMs/univariate_single_step.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @Time : 2022/1/18 14:27 4 | @Author :KI 5 | @File :univariate_single_step.py 6 | @Motto:Hungry And Humble 7 | 8 | """ 9 | import os 10 | import sys 11 | 12 | curPath = os.path.abspath(os.path.dirname(__file__)) 13 | rootPath = os.path.split(curPath)[0] 14 | sys.path.append(rootPath) 15 | 16 | from util import train, test, load_data 17 | from args import us_args_parser 18 | from data_process import setup_seed 19 | 20 | setup_seed(20) 21 | path = os.path.abspath(os.path.dirname(os.getcwd())) 22 | LSTM_PATH = path + '/models/univariate_single_step.pkl' 23 | # print(LSTM_PATH) 24 | 25 | 26 | if __name__ == '__main__': 27 | args = us_args_parser() 28 | flag = 'us' 29 | Dtr, Val, Dte, m, n = load_data(args, flag) 30 | train(args, Dtr, Val, LSTM_PATH) 31 | test(args, Dte, LSTM_PATH, m, n) 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://img.shields.io/badge/LSTM-Load%20Forecasting-red) 2 | # LSTM-Load-Forecasting 3 | Implementation of Electric Load Forecasting Based on LSTM(BiLSTM). Including Univariate-SingleStep forecasting, Multivariate-SingleStep forecasting and Multivariate-MultiStep forecasting. 4 | 5 | # Environment 6 | pytorch==1.10.1+cu111 7 | 8 | numpy==1.18.5 9 | 10 | pandas==1.2.3 11 | 12 | # Tree 13 | ```bash 14 | . 15 | │ args.py 16 | │ data_process.py 17 | │ LICENSE 18 | │ models.py 19 | │ README.md 20 | │ tree.txt 21 | │ util.py 22 | │ 23 | ├─data 24 | │ data.csv 25 | │ 26 | ├─LSTMs 27 | │ multivariate_multi_step.py 28 | │ multivariate_single_step.py 29 | │ univariate_single_step.py 30 | │ 31 | └─models 32 | multivariate_multi_step.pkl 33 | multivariate_single_step.pkl 34 | univariate_single_step.pkl 35 | ``` 36 | 1. **args.py** is a parameter configuration file, where you can set model parameters and training parameters. 37 | 2. **data_process.py** is the data processing file. If you need to use your own data, then you can modify the load_data function in data_process.py. 38 | 3. Two models are defined in **models.py**, including LSTM and bidirectional LSTM. 39 | 4. **util.py** defines the training and testing functions of the models in the three prediction methods. 40 | 5. The trained model is saved in the **models** folder, which can be used directly for testing. 41 | 6. Data files in csv format are saved under the **data** file. 42 | # Usage 43 | First switch the working path: 44 | ```bash 45 | cd LSTMs/ 46 | ``` 47 | Then, execute in sequence: 48 | ```bash 49 | python multivariate_multi_step.py --epochs 50 --batch_size 30 50 | python multivariate_single_step.py --epochs 30 --batch_size 30 51 | python univariate_single_step.py --epochs 30 --batch_size 30 52 | ``` 53 | If you need to change the parameters, please modify them manually in args.py. 54 | # Result 55 | ![在这里插入图片描述](https://img-blog.csdnimg.cn/2afb0a892c854ca39a46263b25b57d5a.png#pic_center) 56 | -------------------------------------------------------------------------------- /__pycache__/args.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ki-ljl/LSTM-Load-Forecasting/78ff930057255809659680e4a466dd57465d78c6/__pycache__/args.cpython-37.pyc -------------------------------------------------------------------------------- /__pycache__/data_process.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ki-ljl/LSTM-Load-Forecasting/78ff930057255809659680e4a466dd57465d78c6/__pycache__/data_process.cpython-37.pyc -------------------------------------------------------------------------------- /__pycache__/models.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ki-ljl/LSTM-Load-Forecasting/78ff930057255809659680e4a466dd57465d78c6/__pycache__/models.cpython-37.pyc -------------------------------------------------------------------------------- /__pycache__/util.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ki-ljl/LSTM-Load-Forecasting/78ff930057255809659680e4a466dd57465d78c6/__pycache__/util.cpython-37.pyc -------------------------------------------------------------------------------- /models/multivariate_multi_step.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ki-ljl/LSTM-Load-Forecasting/78ff930057255809659680e4a466dd57465d78c6/models/multivariate_multi_step.pkl -------------------------------------------------------------------------------- /models/multivariate_single_step.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ki-ljl/LSTM-Load-Forecasting/78ff930057255809659680e4a466dd57465d78c6/models/multivariate_single_step.pkl -------------------------------------------------------------------------------- /models/univariate_single_step.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ki-ljl/LSTM-Load-Forecasting/78ff930057255809659680e4a466dd57465d78c6/models/univariate_single_step.pkl -------------------------------------------------------------------------------- /tree.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ki-ljl/LSTM-Load-Forecasting/78ff930057255809659680e4a466dd57465d78c6/tree.txt --------------------------------------------------------------------------------