├── .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 |
10 |
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 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/other.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
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 |
362 |
363 | 1646136315444
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
434 |
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 | 
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 | 
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
--------------------------------------------------------------------------------