%% II. 训练集/测试集产生
clear all
%%
% 1. 导入数据
a=xlsread('alldata.xlsx');
x=a(:,2:22)
y=a(:,28)
x1= x([2:2:100],:)
x2= x([102:2:200],:)
x3= x([202:2:300],:)
x4= x([302:2:400],:)
x5= x([402:2:500],:)
x6= x([502:2:600],:)
x7= x([602:2:700],:)
x8= x([702:2:800],:)
x9= x([802:2:900],:)
x10= x([902:2:1000],:)
x11= x([1002:2:1100],:)
x12= x([1102:2:1200],:)
x13= x([1202:2:1300],:)
x14= x([1302:2:1400],:)
x15= x([1402:2:1500],:)
x16= x([1502:2:1600],:)
x17= x([1602:2:1700],:)
x18= x([1702:2:1800],:)
x19= x([1802:2:1900],:)
x20= x([1902:2:2000],:)
x21= x([2002:2:2100],:)
x22= x([2102:2:2200],:)
traininput=cat(1,x1,x2,x3, x4, x5, x6, x7,x8, x9, x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22)'
%%
xx1= x([1:2:99],:)
xx2= x([101:2:199],:)
xx3= x([201:2:299],:)
xx4= x([301:2:399],:)
xx5= x([401:2:499],:)
xx6= x([501:2:599],:)
xx7= x([601:2:699],:)
xx8= x([701:2:799],:)
xx9= x([801:2:899],:)
xx10= x([901:2:999],:)
xx11= x([1001:2:1099],:)
xx12= x([1101:2:1199],:)
xx13= x([1201:2:1299],:)
xx14= x([1301:2:1399],:)
xx15= x([1401:2:1499],:)
xx16= x([1501:2:1599],:)
xx17= x([1601:2:1699],:)
xx18= x([1701:2:1799],:)
xx19= x([1801:2:1899],:)
xx20= x([1901:2:1999],:)
xx21= x([2001:2:2099],:)
xx22= x([2101:2:2199],:)
testinput=cat(1,xx1,xx2,xx3, xx4, xx5, xx6, xx7,xx8, xx9, xx10,xx11,xx12,xx13,xx14,xx15,xx16,xx17,xx18,xx19,xx20,xx21,xx22)'
y1= y([2:2:100] )
y2= y([102:2:200] )
y3= y([202:2:300] )
y4= y([302:2:400] )
y5= y([402:2:500] )
y6= y([502:2:600] )
y7= y([602:2:700] )
y8= y([702:2:800] )
y9= y([802:2:900] )
y10= y([902:2:1000] )
y11= y([1002:2:1100] )
y12= y([1102:2:1200] )
y13= y([1202:2:1300] )
y14= y([1302:2:1400] )
y15= y([1402:2:1500] )
y16= y([1502:2:1600] )
y17= y([1602:2:1700] )
y18= y([1702:2:1800] )
y19= y([1802:2:1900] )
y20= y([1902:2:2000] )
y21= y([2002:2:2100] )
y22= y([2102:2:2200] )
trainoutput=cat(1, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21, y22)'
%%
yy1= y([1:2:99] )
yy2= y([101:2:199] )
yy3= y([201:2:299] )
yy4= y([301:2:399] )
yy5= y([401:2:499] )
yy6= y([501:2:599] )
yy7= y([601:2:699] )
yy8= y([701:2:799] )
yy9= y([801:2:899] )
yy10= y([901:2:999] )
yy11= y([1001:2:1099] )
yy12= y([1101:2:1199] )
yy13= y([1201:2:1299] )
yy14= y([1301:2:1399] )
yy15= y([1401:2:1499] )
yy16= y([1501:2:1599] )
yy17= y([1601:2:1699] )
yy18= y([1701:2:1799] );
yy19= y([1801:2:1899] );
yy20= y([1901:2:1999] );
yy21= y([2001:2:2099] );
yy22= y([2101:2:2199] );
testoutput=cat(1, yy1, yy2, yy3, yy4, yy5, yy6, yy7, yy8, yy9, yy10, yy11, yy12, yy13, yy14, yy15, yy16, yy17, yy18, yy19, yy20, yy21, yy22)'
%% III. 数据归一化
[train_input, YS] = mapminmax(traininput,0,1);
test_input = mapminmax('apply',testinput,YS);
%%
[train_output, YS1] = mapminmax(trainoutput,0,1);
test_output = mapminmax('apply',testoutput,YS1);
%%
net = newff(train_input,train_output,10)
net=train(net,train_input,train_output)
% 2. 设置训练参数
net.trainParam.epochs = 1000;
net.trainParam.goal = 1e-3;
net.trainParam.lr = 0.01;
yp=net(train_input)
% 5. 数据反归一化
T_sim = round(mapminmax('reverse',yp,YS1));
t=T_sim-trainoutput
b=(t==0);
n=sum(b(:))
网友评论