mirror of
https://github.com/wassname/ETSformer.git
synced 2026-07-15 11:19:20 +08:00
49 KiB
49 KiB
In [1]:
import os
os.sys.path.append('..')In [2]:
import argparse
import os
import torch
from exp.exp_main import Exp_Main
import random
import numpy as np
In [3]:
Exp = Exp_Main
ExpOut [3]:
exp.exp_main.Exp_Main
In [4]:
import warnings
warnings.simplefilter("ignore")
# autoreload import your package
%load_ext autoreload
%autoreload 2In [5]:
from loguru import logger
logger.remove()
logger.add(os.sys.stdout, level="ERROR", colorize=True, format="<level>{time} | {message}</level>")
# import_dir(ta_dir, verbose=False)
warnings.simplefilter("ignore")In [6]:
import torch
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inlineIn [7]:
from run import set_seed, get_args, Exp_MainIn [9]:
# mimic cli args to avoid code duplication
argv = """python -u run.py \
--root_path ../dataset/exchange_rate/ \
--data_path exchange_rate.csv \
--model_id Exchange \
--model ETSformer \
--data custom \
--features S \
--seq_len 96 \
--pred_len 96 \
--e_layers 2 \
--d_layers 2 \
--enc_in 1 \
--dec_in 1 \
--c_out 1 \
--des 'Exp' \
--K 0 \
--learning_rate 1e-3 \
--itr 1
"""
argv = argv.replace("\\n", "").split()[3:]
args = get_args(argv)
args
Exp = Exp_Main
ii=0
set_seed(ii)
# setting record of experiments
setting = '{}_{}_{}_ft{}_sl{}_pl{}_dm{}_nh{}_el{}_dl{}_df{}_K{}_lr{}_{}_{}'.format(
args.model_id,
args.model,
args.data,
args.features,
args.seq_len,
args.pred_len,
args.d_model,
args.n_heads,
args.e_layers,
args.d_layers,
args.d_ff,
args.K,
args.learning_rate,
args.des, ii)
# if os.path.exists(os.path.join(args.checkpoints, setting)):
# print('skipping exists')
# continue
exp = Exp(args) # set experiments
print('>>>>>>>start training : {}>>>>>>>>>>>>>>>>>>>>>>>>>>'.format(setting))
exp.train(setting)
print('>>>>>>>testing : {}<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'.format(setting))
exp.test(setting, data='val')
exp.test(setting, data='test')
torch.cuda.empty_cache()Args in experiment: Namespace(K=0, activation='sigmoid', batch_size=32, c_out=1, checkpoints='./checkpoints/', d_ff=2048, d_layers=2, d_model=512, damping_learning_rate=0, data='custom', data_path='exchange_rate.csv', dec_in=1, des="'Exp'", devices='0,1,2,3', dropout=0.2, e_layers=2, embed='timeF', enc_in=1, features='S', freq='h', gpu=0, itr=1, label_len=0, learning_rate=0.001, lradj='exponential_with_warmup', min_lr=1e-30, model='ETSformer', model_id='Exchange', n_heads=8, num_workers=10, optim='adam', output_attention=False, patience=5, pred_len=96, root_path='../dataset/exchange_rate/', seq_len=96, smoothing_learning_rate=0, std=0.2, target='OT', train_epochs=15, use_gpu=True, use_multi_gpu=False, warmup_epochs=3) Use GPU: cuda:0 >>>>>>>start training : Exchange_ETSformer_custom_ftS_sl96_pl96_dm512_nh8_el2_dl2_df2048_K0_lr0.001_'Exp'_0>>>>>>>>>>>>>>>>>>>>>>>>>> train 5120 val 665 test 1422 iters: 100, epoch: 1 | loss: 0.1855393 speed: 0.0262s/iter; left time: 60.1997s Epoch: 1 cost time: 4.017645359039307 Epoch: 1, Steps: 160 | Train Loss: 0.3291200 Vali Loss: 0.1620757 Test Loss: 0.0996447 Validation loss decreased (inf --> 0.162076). Saving model ... Updating learning rate to 0.00025 iters: 100, epoch: 2 | loss: 0.3449063 speed: 0.0523s/iter; left time: 111.9286s Epoch: 2 cost time: 4.011619567871094 Epoch: 2, Steps: 160 | Train Loss: 0.2371088 Vali Loss: 0.1372457 Test Loss: 0.0956475 Validation loss decreased (0.162076 --> 0.137246). Saving model ... Updating learning rate to 0.0005 iters: 100, epoch: 3 | loss: 0.1758220 speed: 0.0541s/iter; left time: 107.2494s Epoch: 3 cost time: 4.069975852966309 Epoch: 3, Steps: 160 | Train Loss: 0.2245417 Vali Loss: 0.1412140 Test Loss: 0.0931368 EarlyStopping counter: 1 out of 5 Updating learning rate to 0.00075 iters: 100, epoch: 4 | loss: 0.2099838 speed: 0.0532s/iter; left time: 96.8687s Epoch: 4 cost time: 3.987823724746704 Epoch: 4, Steps: 160 | Train Loss: 0.2288409 Vali Loss: 0.1397144 Test Loss: 0.0937123 EarlyStopping counter: 2 out of 5 Updating learning rate to 0.001 iters: 100, epoch: 5 | loss: 0.2285676 speed: 0.0525s/iter; left time: 87.2150s Epoch: 5 cost time: 4.027522563934326 Epoch: 5, Steps: 160 | Train Loss: 0.2344545 Vali Loss: 0.1622206 Test Loss: 0.0896547 EarlyStopping counter: 3 out of 5 Updating learning rate to 0.0005 iters: 100, epoch: 6 | loss: 0.2818964 speed: 0.0529s/iter; left time: 79.3673s Epoch: 6 cost time: 4.119000196456909 Epoch: 6, Steps: 160 | Train Loss: 0.2204486 Vali Loss: 0.1501924 Test Loss: 0.0886038 EarlyStopping counter: 4 out of 5 Updating learning rate to 0.00025 iters: 100, epoch: 7 | loss: 0.1605041 speed: 0.0566s/iter; left time: 75.9389s Epoch: 7 cost time: 4.324657917022705 Epoch: 7, Steps: 160 | Train Loss: 0.2194144 Vali Loss: 0.1449849 Test Loss: 0.0917771 EarlyStopping counter: 5 out of 5 Early stopping >>>>>>>testing : Exchange_ETSformer_custom_ftS_sl96_pl96_dm512_nh8_el2_dl2_df2048_K0_lr0.001_'Exp'_0<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< val 665 loading model test shape: (20, 32, 96, 1) (20, 32, 96, 1) test shape: (640, 96, 1) (640, 96, 1) mse:0.13651615381240845, mae:0.2945910394191742 test 1422 loading model test shape: (44, 32, 96, 1) (44, 32, 96, 1) test shape: (1408, 96, 1) (1408, 96, 1) mse:0.09564752131700516, mae:0.2282976359128952
In [10]:
In [11]:
settingOut [11]:
"Exchange_ETSformer_custom_ftS_sl96_pl96_dm512_nh8_el2_dl2_df2048_K0_lr0.001_'Exp'_0"
In [12]:
ds, dl = exp._get_data('test')test 1422
In [13]:
preds, trues = exp.test(setting, data='test')test 1422 loading model test shape: (44, 32, 96, 1) (44, 32, 96, 1) test shape: (1408, 96, 1) (1408, 96, 1) mse:0.09564752131700516, mae:0.2282976359128952
In [14]:
%matplotlib inlineIn [15]:
i=990
(batch_x, batch_y, batch_x_mark, batch_y_mark) = ds[i]
l1 = batch_x.shape[0]
l2 = batch_y.shape[0]
plt.plot(range(l1), batch_x[:, -1], label='past')
plt.plot(range(l1, l1+l2), batch_y[:, -1], color='blue', ls='--', label='true')
plt.plot(range(l1, l1+l2), preds[i], label='pred');
plt.legend(loc='lower left')Out [15]:
<matplotlib.legend.Legend at 0x7f692aef6730>
In [ ]:
In [ ]:
In [ ]: