天天看点

神经网络预测路温

神经网络预测路温

(笔记,自用)

训练输入:12/1-2/29每分钟的主站点气温、露点、湿度

训练输出:12/1-2/29每分钟的主站点路温

测试输入:某时间(冬天时间最佳)主站点气温、露点、湿度

测试输出:某时间(冬天时间最佳)路温

代码如下:

clc;
clear all;
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 25-Nov-2019 14:58:54
%
% This script assumes these variables are defined:
%
%   inputs - input data.
%   targets - target data.

x=xlsread('HaiDian_HD002_StationRTW_ALL.xlsx','D42187:F172574');%12/1-2/29的数据
y=xlsread('HaiDian_HD002_StationRTW_ALL.xlsx','G42187:G172574');%交通站路温列
inputs = x';%转置
targets = y';
x = inputs;
t = targets;

% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainlm';  % Levenberg-Marquardt backpropagation.

% Create a Fitting Network
hiddenLayerSize = 10;
net = fitnet(hiddenLayerSize,trainFcn);

% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;

% Train the Network
[net,tr] = train(net,x,t);

% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y);

% View the Network
% view(net)

% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)
z=xlsread('HaiDian_HD002_StationRTW_ALL.xlsx','D172574:F172754');%预测的数据
testinputs= z';%转置
testoutputs = net(testinputs);%预测结果值
a=xlsread('HaiDian_HD002_StationRTW_ALL.xlsx','G172574:G172754');%实际的数据
A=a';
B=testoutputs;
E=A-B;
figure,plot(A,'r');hold on
plot(B,'b');hold on
plot(E,'g');
grid on
 xlabel('预测时间点')
 ylabel('温度值')
legend('实际值','预测值','误差值')
title('预测结果对比');

% xlswrite('HaiDian_HD002_StationRTW_ALL.xlsx',testoutputs','H172574');

%如果训练满意,可以保存训练好网络(保存文件名,网络名,)
%save('training_net.mat','net','tr');
           

继续阅读