%实现的分类结果真的不好,才0.3+,这里只是简单的说明怎么使用函数,至于实现达不到效果的问题,后续会研究
clear all
clc
%% 读入数据
xlsfile='train.txt';
x = load(xlsfile);
[m,n] = size(x);
traind = x(:,1:n-1);
label = x(:,n);
testl = load('result.txt');
testd = load('test.txt');
%% 数据处理
%标准化处理
% [traind,MU,SIGMA] = zscore(traind);
% [testd,MU,SIGMA] = zscore(testd);
%归一化处理
[traind,G] = mapminmax(traind);
[testd,G] = mapminmax(testd);
%%
P = traind';
T = label';
test_p = testd';
test_pl = testl';
%% 使用newff函数
ff=newff(P,T,30); % 建立一个BP网络,包含一个20个节点的隐含层
ff.trainParam.epochs = 50;
ff = train(ff,P,T); % 训练
Y1= sim(ff,test_p); % 仿真
Y1_init = Y1;
% 取整
Y1(Y1<0.5)=0;
Y1(Y1>=0.5)=1;
rate1 = sum(Y1 == test_pl)/length(Y1);
%% 使用newcf函数
% cf=newcf(P,T,20); % 用newcf建立前向网络
% cf.trainParam.epochs = 50;
% cf = train(cf,P,T); % 训练
% Y2 = sim(cf,test_p);% 仿真
%
% Y2_init = Y2;
%
% % 取整
% Y2(Y2<0.5)=0;
% Y2(Y2>=0.5)=1;
% rate2 = sum(Y2 == test_pl)/length(Y2);
%% 使用newfftd函数
% net = newfftd(P,T,[0 1],5);% 创建隐含层包含5个神经元的BP网络
% net.trainParam.epochs = 100;
%
% net.trainParam.lr=0.1;
% net.trainParam.goal=0.0000004;
%
% net = train(net,P,T);
% Y3 = net(test_p);
%
% Y3_init = Y3;
%
% % 取整
% Y3(Y3<0.5)=0;
% Y3(Y3>=0.5)=1;
% rate3= sum(Y3 == test_pl)/length(Y3);
%% 使用newrb或者newgrnn函数
%net=newrb(P,T,0,0.6);
% net = newgrnn(P,T);
% Y4=sim(net,test_p);
%
% Y4_init = Y4;
% % 取整
% Y4(Y4<0.5)=0;
% Y4(Y4>=0.5)=1;
% rate4= sum(Y4 == test_pl)/length(Y4);