套娃!双路+双向!TCN-Transformer+BiLSTM多变量时间序列预测(Matlab)
目录
效果一览
基本介绍
1.Matlab实现双路+双向!TCN-Transformer+BiLSTM多变量时间序列预测(Matlab)!
2.运行环境为Matlab2023b及以上;
3.data为数据集,输入多个特征,输出单个变量,考虑历史特征的影响,多变量时间序列预测,main.m为主程序,运行即可,所有文件放在一个文件夹;
4.命令窗口输出R2、MSE、RMSE、MAE、MAPE等多指标评价;
程序设计
- 完整程序和数据下载私信博主回复TCN-Transformer+BiLSTM多变量时间序列预测(Matlab)。
%% 划分数据集
for i = 1: num_samples - kim - zim + 1
res(i, :) = [reshape(result(i: i + kim - 1, :), 1, kim * or_dim), result(i + kim + zim - 1, :)];
end
%% 数据集分析
outdim = 1; % 最后一列为输出
num_size = 0.7; % 训练集占数据集比例
num_train_s = round(num_size * num_samples); % 训练集样本个数
f_ = size(res, 2) - outdim; % 输入特征维度
%% 划分训练集和测试集
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);
%% 转置以适应模型
p_train = p_train'; p_test = p_test';
t_train = t_train'; t_test = t_test';
%% 参数设置
fun = @getObjValue; % 目标函数
dim = 2; % 优化参数个数
lb = [0.1, 0.1]; % 优化参数目标下限
ub = [ 800, 800]; % 优化参数目标上限
pop = 20; % 种群数量
Max_iteration = 30; % 最大迭代次数
%% 优化算法
[Best_score,Best_pos, curve] = SSA(pop, Max_iteration, lb, ub, dim, fun);
%% 获取最优参数
bestc = Best_pos(1, 1);
bestg = Best_pos(1, 2);
参考资料
标签:Transformer,套娃,%%,双路,num,train,Matlab,res,test From: https://blog.csdn.net/kjm13182345320/article/details/142501890[1] https://blog.csdn.net/kjm13182345320/article/details/128163536?spm=1001.2014.3001.5502
[2] https://blog.csdn.net/kjm13182345320/article/details/128151206?spm=1001.2014.3001.5502