%环境准备
%清理工作区间及命令窗口
clc;clear;
warning off;
%导入数据
data=xlsread('data');
%准备输入和输出训练数据
input =data(:,1:4)';
output=data(:,5)';
nwhole =size(data,1);
train_ratio=0.95;
ntrain=round(nwhole*train_ratio);
ntest =nwhole-ntrain;
input_train =input(:,1:ntrain);
output_train=output(:,1:ntrain);
input_test =input(:, ntrain+1:ntrain+ntest);
output_test=output(:,ntrain+1:ntrain+ntest);
%归一化(全部特征 均归一化)
[inputn_train,inputps] =mapminmax(input_train);
[outputn_train,outputps]=mapminmax(output_train);
inputn_test =mapminmax('apply',input_test,inputps);
outputn_test=mapminmax('apply',output_test,outputps);
%特征维度确定
%数据输入x的特征维度
inputSize = size(inputn_train,1);
%数据输出y的维度
outputSize = size(outputn_train,1);
%可以增加对照实验确定
numhidden_units=200;
%BiLSTM 层参数设置
%输入层设置 sequenceInputLayer
%学习层设置 bilstmLayer
%全连接层设置 fullyConnectedLayer
%epoch后学习率更新
%% bilstm
layers = [ ...
sequenceInputLayer(inputSize)
bilstmLayer(numhidden_units)
dropoutLayer(0.2)
fullyConnectedLayer(outputSize)
regressionLayer('name','out')];
%% trainoption(bilstm)
opts = trainingOptions('adam', ...
'MaxEpochs',200, ...
'GradientThreshold',1,...
'ExecutionEnvironment','cpu',...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',100, ...
'LearnRateDropFactor',0.8, ...
'Verbose',0, ...
'Plots','training-progress'...
);
%BiLSTM网络训练
tic
BiLSTMnet = trainNetwork(inputn_train ,outputn_train ,layers,opts);
toc;
[BiLSTMnet,BiLSTMoutputr_train]= predictAndUpdateState(BiLSTMnet,inputn_train);
BiLSTMoutput_train = mapminmax('reverse',BiLSTMoutputr_train,outputps);
%BiLSTM网络测试
[BiLSTMnet,BiLSTMoutputr_test] = predictAndUpdateState(BiLSTMnet,inputn_test);
%网络输出反归一化
BiLSTMoutput_test= mapminmax('reverse',BiLSTMoutputr_test,outputps);
%BiLSTM数据评价
error_test=BiLSTMoutput_test'-output_test';
pererror_test=error_test./output_test';
error=error_test';
pererror=pererror_test';
avererror=sum(abs(error))/(ntest);
averpererror=sum(abs(pererror))/(ntest);
RMSE = sqrt(mean((error).^2));
disp('BiLSTM网络预测绝对平均误差MAE');
disp(avererror);
disp('BiLSTM网络预测平均绝对误差百分比MAPE');
disp(averpererror)
disp('BiLSTM网络预测均方根误差RMSE')
disp(RMSE)
% 数据可视化分析
%测试数据
figure()
plot(BiLSTMoutput_test,'r-.')
hold on
plot(output_test,'k--')
legend( '预测测试数据','实际分析数据','Location','NorthWest','FontName','仿宋');
title('BiLSTM网络模型结果及真实值','fontsize',15,'FontName','仿宋')
xlabel('样本','fontsize',10,'FontName','仿宋');
ylabel('数值','fontsize',10,'FontName','仿宋');
%-------------------------------------------------------------------------------------
figure()
stairs(pererror_test,'-.','Color',[255 50 0]./255,'linewidth',1)
legend('BiLSTM网络测试相对误差','Location','NorthEast','FontName','仿宋')
title('BiLSTM网络预测相对误差','fontsize',10,'FontName','仿宋')
ylabel('误差','fontsize',10,'FontName','仿宋')
xlabel('样本','fontsize',10,'FontName','仿宋')
%-------------------------------------------------------------------------------------
没有合适的资源?快使用搜索试试~ 我知道了~
【LSTM回归预测】基于双向长短时记忆BiLSTM数据回归预测(多输入单输出)含Matlab源码.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共5个文件
jpg:3个
xlsx:1个
m:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
![star](https://csdnimg.cn/release/downloadcmsfe/public/img/star.98a08eaa.png)
温馨提示
【LSTM回归预测】基于双向长短时记忆BiLSTM数据回归预测(多输入单输出)含Matlab源码.zip
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/XLSX.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
共 5 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- 2301_765180782023-04-24资源和描述一致,质量不错,解决了我的问题,感谢资源主。
![avatar](https://profile-avatar.csdnimg.cn/0952dabfe4084a058a29f6b3884c6064_qq_59747472.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
天天Matlab科研工作室
- 粉丝: 3w+
- 资源: 7249
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)