目录
效果一览
基本介绍
1.负荷预测 | Matlab基于TCN-LSTM-Attention单变量时间序列多步预测;
2.单变量时间序列数据集,采用前12个时刻预测未来96个时刻的数据;
3.excel数据方便替换,运行环境matlab2023及以上,展示最后96个时间步的预测对比图,评价指标MAE、MAPE、RMSE、MSE、R2;
4.程序语言为matlab,程序可出预测效果图,迭代优化图,相关分析图;
5.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。
Attention(注意力机制):注意力机制用于加强模型对序列中不同位置的重要性的关注。通过计算每个时间步的注意力权重,模型可以自动学习并关注序列中最相关的部分。
程序设计
- 完整程序和数据获取方式:私信博主回复Matlab基于TCN-LSTM-Attention单变量时间序列多步预测。
python
P_train = res(1: num_train_s, 1: f_)';
T_train = res(1: num_train_s, f_ + 1: end)';
M = size(P_train, 2);
P_test = res(num_train_s + 1: end, 1: f_)';
T_test = res(num_train_s + 1: end, f_ + 1: end)';
N = size(P_test, 2);
% 数据归一化
[p_train, ps_input] = mapminmax(P_train, 0, 1);
p_test = mapminmax('apply', P_test, ps_input);
[t_train, ps_output] = mapminmax(T_train, 0, 1);
t_test = mapminmax('apply', T_test, ps_output);
% 格式转换
for i = 1 : M
vp_train{i, 1} = p_train(:, i);
vt_train{i, 1} = t_train(:, i);
end
for i = 1 : N
vp_test{i, 1} = p_test(:, i);
vt_test{i, 1} = t_test(:, i);
end
lgraph = connectLayers(lgraph,outputName,"flatten");
lgraph = connectLayers(lgraph,"flatten","gru1");
lgraph = connectLayers(lgraph,"flatten","flip3");
lgraph = connectLayers(lgraph,"gru1","concat/in1");
lgraph = connectLayers(lgraph,"gru2","concat/in2");
% 参数设置
options0 = trainingOptions('adam', ... % 优化算法Adam
'MaxEpochs', 150, ... % 最大训练次数
'GradientThreshold', 1, ... % 梯度阈值
'InitialLearnRate', 0.01, ... % 初始学习率
'LearnRateSchedule', 'piecewise', ... % 学习率调整
'LearnRateDropPeriod',100, ... % 训练100次后开始调整学习率
'LearnRateDropFactor',0.001, ... % 学习率调整因子
'L2Regularization', 0.001, ... % 正则化参数
'ExecutionEnvironment', 'cpu',... % 训练环境
'Verbose', 1, ... % 关闭优化过程
'Plots', 'none'); % 画出曲线
参考资料
[2] https://download.csdn.net/download/kjm13182345320/87568090?spm=1001.2014.3001.5501
[3] https://blog.csdn.net/kjm13182345320/article/details/129433463?spm=1001.2014.3001.5501