【bayes-Transformer-GRU多维时序预测】多变量输入模型。matlab代码,2023b及其以上
% 1. 数据准备
X_train = 训练数据输入;
Y_train = 训练数据输出;
X_test = 测试数据输入;
% 2. 模型构建
inputSize = size(X_train, 2);
numHiddenUnits = 100;
numResponses = 1;
layers = [ …
sequenceInputLayer(inputSize)
biLSTMLayer(numHiddenUnits, ‘OutputMode’, ‘sequence’)
dropoutLayer(0.2)
fullyConnectedLayer(numResponses)
regressionLayer
];
options = trainingOptions(‘adam’, …
‘MaxEpochs’,50, …
‘MiniBatchSize’, 32, …
‘GradientThreshold’, 1, …
‘SequenceLength’, 20, …
‘Plots’,‘training-progress’);
% 3. 贝叶斯优化
vars = [
optimizableVariable(‘MiniBatchSize’,[32, 128],‘Type’,‘integer’)
optimizableVariable(‘SequenceLength’,[10, 30],‘Type’,‘integer’)
];
ObjFcn = @(params)trainBiGRU(params, X_train, Y_train, layers, options);
results = bayesopt(ObjFcn, vars, ‘MaxObjectiveEvaluations’, 30);
% 4. 训练模型
bestParams = bestPoint(results);
bestMiniBatchSize = bestParams.MiniBatchSize;
bestSequenceLength = bestParams.SequenceLength;
options.MiniBatchSize = bestMiniBatchSize;
options.SequenceLength = bestSequenceLength;
net = trainNetwork(X_train, Y_train, layers, options);
% 5. 模型评估
YPred = predict(net, X_test);
% 6. 预测
disp(YPred);
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_59771180/article/details/143499678
原文地址:https://blog.csdn.net/qq_59771180/article/details/143662185
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!