%实现的分类结果真的不好,才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