VMD-SSA-LSTM基于变分模态分解和麻雀算法优化长短期记忆网络的时间序列预测MATLAB代码(含LSTM、VMD-LSTM、VMD-SSA-LSTM等模型的对比)。

VMD-SSA-LSTM基于变分模态分解和麻雀算法优化长短期记忆网络的时间序列预测MATLAB代码(含LSTM、VMD-LSTM、VMD-SSA-LSTM等模型的对比)。_第1张图片

clc;

clear all

close all

%% VMD-SSA-LSTM预测

tic

load vmd_data.mat

load lstm.mat

disp('…………………………………………………………………………………………………………………………')

disp('VMD-SSA-LSTM预测')

disp('…………………………………………………………………………………………………………………………')

%% 建立

T_sim5 =[];

T_sim6 =[];

data1 = u';

for i = 1:size(data1,2)

disp(['对第',num2str(i),'个分量进行建模'])

data2= data1(:,i);

num_samples = length(data2); % 样本个数

kim = 5; % 延时步长(kim个历史数据作为自变量)

zim = 1; % 跨zim个时间点进行预测

or_dim = size(data2,2);

res=[];

% 重构数据集

for i = 1: num_samples - kim - zim + 1

res(i, :) = [reshape(data2(i: i + kim - 1,:), 1, kim*or_dim), data2(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);

你可能感兴趣的:(lstm,机器学习,深度学习)