%% 神经网络二分类问题
clc,clear,close all
%% 对照组指标数据 0组
p1=[0.73 9.9 512.6 0.000488341 94.23
0.58 13.3 105.5 0.00028624 123.86
0.52 12.8 596.4 0.000898535 105.47
0.41 12.7 621.9 0.003519715 110.65
0.51 9 342 0.001070026 123.61
0.73 11.7 237.4 0.000592125 103.07
0.72 10.6 670.1 0.001646966 108.40
0.61 11.2 210.8 0.000714758 125.00
0.6 7.1 614.7 0.002473218 112.82
0.62 6 234.8 0.011008547 128.19
0.6 7.3 126.5 0.001716387 118.42
0.53 8 506.6 0.002412081 140.29
0.6 9.9 254.8 0.00047552 124.17
0.58 11.9 376.7 0.001550388 112.13
0.62 10.7 570.5 0.001077933 125.78
0.79 8.5 105.9 0.000389824 105.67
0.81 7.6 137.8 0.000960825 112.74
0.56 5.7 148.6 0.001310584 117.40
0.63 7.5 97 0.001244019 119.11
]; %归为0
%% 实验组指标数据 1组
p2=[0.88 14.1 168.9 0.00319027 104.30
0.67 7.2 141.2 0.000685297 90.61
0.9 9.4 298.5 0.004820393 90.46
0.68 10.8 70.3 0.000395073 98.36
1.25 9.2 1614.6 0.076472875 87.21
0.5 9.2 210.2 0.001139238 115.26
0.72 12.6 132.4 0.00102688 81.74
0.64 8.6 243.9 0.000489883 114.94
0.97 16.9 581.4 0.005763578 68.53
0.67 10.6 242.8 0.00101917 95.64
0.54 7 372.6 0.002005217 123.43
0.86 10.1 172.4 0.002088703 85.23
0.68 13.6 213.1 0.001856427 115.22
2.16 37.1 2206.6 0.027308957 33.12
1.02 21.5 75.3 0.010366863 70.40
0.73 11.8 100.8 0.000373529 109.38
3.14 22.1 1727.2 0.942625053 9.11
0.77 9.8 103.3 0.001319323 119.84
0.64 10.8 100.1 0.028400355 120.72
1.85 18.4 4761.6 0.232148915 31.60
0.84 7.7 93.3 0.001710846 96.96
1.3 9.8 410.1 0.570991575 74.78
]; %归为1
%% 结果标签
flag = [ones(size(p1,1),1); zeros(size(p2,1),1)];
%% 神经网络
p=[p1;p2]';
pr=minmax(p);
goal=[ones(1,size(p1,1)),zeros(1,size(p2,1));zeros(1,size(p1,1)),ones(1,size(p2,1))];
% plot(p1(:,1),p1(:,2),'h',p2(:,1),p2(:,2),'o')
net=newff(pr,[3,2],{'logsig','logsig'}); % 3个隐层,2种传递方式
net.trainParam.show = 10;
net.trainParam.lr = 0.05;
net.trainParam.goal = 1e-10; % 容忍误差
net.trainParam.epochs = 1000; % 迭代次数
net = train(net,p,goal);
%% 训练结果
outcome = sim(net,p) ;%给p1和p2分类作用,分为0和1
train_predict(outcome(1,:) >= 0.5,1) = 1;
train_predict(outcome(1,:) < 0.5,1) = 0;
true = sum(1 - abs(flag - train_predict)) / size(flag,1)
%% 预测
%{
x = [55 0.89 2.89 1.16 1.03
461.7 0.97 1.13 1.37 0.47
148.3 0.49 1.56 0.71 0.66
]'; % 指标数据
y = sim(net,x) %给待鉴定样本分类
test_predict(y(1,:) >= 0.5,1) = 1;
test_predict(y(1,:) < 0.5,1) = 0;
%}