LSTM-ANN基于长短期记忆神经网络结合人工神经网络的多变量回归预测Matlab
目录
预测结果
评价指标
训练集数据的R2为:0.99805
测试集数据的R2为:0.98351
训练集数据的MAE为:14.8716
测试集数据的MAE为:49.7271
训练集数据的MAPE为:0.0041394
测试集数据的MAPE为:0.014129
训练集数据的MBE为:2.0468
测试集数据的MBE为:12.0079
训练集数据的MSE为:563.9512
测试集数据的MSE为:4964.9945
基本介绍
LSTM-ANN基于长短期记忆神经网络结合人工神经网络的多变量回归预测MatlabMatlab
程序设计
%--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 清空环境变量
warning off % 关闭报警信息
close all % 关闭开启的图窗
clear % 清空变量
clc % 清空命令行
%--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 导入数据
re
%--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 划分训练集和测试集
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);
%% 数据反归一化
T_sim1 = mapminmax('reverse', t_sim1, ps_output);
T_sim2 = mapminmax('reverse', t_sim2, ps_output);
%% 均方根误差
error1 = sqrt(sum((T_sim1 - T_train).^2) ./ M);
error2 = sqrt(sum((T_sim2 - T_test ).^2) ./ N);
%% 相关指标计算
% R2
R1 = 1 - norm(T_train - T_sim1)^2 / norm(T_train - mean(T_train))^2;
R2 = 1 - norm(T_test - T_sim2)^2 / norm(T_test - mean(T_test ))^2;
disp(['训练集数据的R2为:', num2str(R1)])
disp(['测试集数据的R2为:', num2str(R2)])
% MAE
mae1 = sum(abs(T_sim1 - T_train)) ./ M ;
mae2 = sum(abs(T_sim2 - T_test )) ./ N ;
disp(['训练集数据的MAE为:', num2str(mae1)])
disp(['测试集数据的MAE为:', num2str(mae2)])
%--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 平均绝对百分比误差MAPE
MAPE1 = mean(abs((T_train - T_sim1)./T_train));
MAPE2 = mean(abs((T_test - T_sim2)./T_test));
disp(['训练集数据的MAPE为:', num2str(MAPE1)])
disp(['测试集数据的MAPE为:', num2str(MAPE2)])
% MBE
mbe1 = sum(T_sim1 - T_train) ./ M ;
mbe2 = sum(T_sim2 - T_test ) ./ N ;
disp(['训练集数据的MBE为:', num2str(mbe1)])
disp(['测试集数据的MBE为:', num2str(mbe2)])
%--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%均方误差 MSE
mse1 = sum((T_sim1 - T_train).^2)./M;
mse2 = sum((T_sim2 - T_test).^2)./N;
disp(['训练集数据的MSE为:', num2str(mse1)])
disp(['测试集数据的MSE为:', num2str(mse2)])
%% 绘图
figure
plot(1: M, T_train, '-', 1: M, T_sim1, '-', 'LineWidth', 1)
legend('真实值', '预测值')
xlabel('预测样本')
ylabel('预测结果')
string = {'训练集预测结果对比'; ['RMSE=' num2str(error1)]};
title(string)
xlim([1, M])
%--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
figure
plot(1: N, T_test, '-', 1: N, T_sim2, '-', 'LineWidth', 1)
legend('真实值', '预测值')
xlabel('预测样本')
ylabel('预测结果')
string = {'测试集预测结果对比'; ['RMSE=' num2str(error2)]};
title(string)
xlim([1, N])
参考资料
标签:disp,%%,ANN,train,num2str,Matlab,test,LSTM,数据 From: https://blog.csdn.net/m0_57362105/article/details/143221772[1] https://blog.csdn.net/m0_57362105/category_12278342.html?spm=1001.2014.3001.5482
[2] https://blog.csdn.net/m0_57362105/article/details/129998935