负荷预测 | Matlab基于TCN-LSTM-Attention单变量时间序列多步预测

目录

效果一览




基本介绍

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');                    % 画出曲线

参考资料

1\] http://t.csdn.cn/pCWSp \[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

相关推荐
西西弗Sisyphus1 天前
从零实现Transformer:第 2 部分 - 缩放点积注意力(Scaled Dot-Product Attention)
transformer·attention·注意力机制·注意力
西西弗Sisyphus2 天前
Transformer 架构里关于 Attention 概念的澄清
transformer·attention·注意力机制·注意力·self-attention
空巢青年_rui16 天前
【翻译】现代LLM中注意力变体的可视化指南:从MHA和GQA到MLA、稀疏注意力机制和混合架构
llm·attention·mha·gqa·dsa·mla·swa
沅_Yuan23 天前
基于核密度估计的CNN-LSTM-Attention-KDE多输入单输出回归模型【MATLAB】
机器学习·回归·cnn·lstm·attention·核密度估计·kde
机器学习之心1 个月前
负荷预测数据集说明文档
负荷预测
bryant_meng1 个月前
【NLP】《The Evolution of NLP: Understanding RNNs, Seq2Seq, and Attention》
人工智能·深度学习·自然语言处理·attention·seq2seq
Sakuraba Ema1 个月前
Attention Residuals:把固定残差换成“跨层注意力”
python·llm·attention
被制作时长两年半的个人练习生3 个月前
【FlashAttention】 FA2与FA1算法区别辨析
attention·cuda
机器学习之心4 个月前
科研绘图 | TCN-LSTM时间卷积神经网络结合长短期记忆神经网络模型结构图
神经网络·tcn-lstm
云雾J视界5 个月前
当算法试图解决一切:技术解决方案主义的诱惑与陷阱
算法·google·bert·transformer·attention·算法治理