-
Notifications
You must be signed in to change notification settings - Fork 1
/
TrainANN_ADASYN.m
81 lines (60 loc) · 1.62 KB
/
TrainANN_ADASYN.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
% train neural net
%%originally created: 20160501
% last modified: 20160611
load inputs;
load targets;
[trainInd,valInd,testInd] = dividerand(3038,90,0,10);
inputstest=(inputs(testInd,:))';
targetstest=(targets(testInd,:))';
[inputsADA, targetsADA] = useADASYN(inputs(trainInd,:), targets(trainInd,:));
inputs=[inputs(trainInd,:);inputsADA]';
targets=[targets(trainInd,:);targetsADA]';
t=[];
for a=1:length(targets)
if targets(a)==1
t(1:2,a)=[1;0];%[1;0]abnormal(1)
else
t(1:2,a)=[0;1];
end
end
targets=t;
t=[];
for a=1:length(targetstest)
if targetstest(a)==1
t(1:2,a)=[1;0];%[1;0]abnormal(1)
else
t(1:2,a)=[0;1];
end
end
targetstest=t;
% Solve a Pattern Recognition Problem with a Neural Network
% Script generated by NPRTOOL
%
% This script assumes these variables are defined:
%
% cancerInputs - input data.
% cancerTargets - target data.
% Create a Pattern Recognition Network
hiddenLayerSize = 35;
net = patternnet(hiddenLayerSize);
% Set up 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,inputs,targets);
% Test the Network
outputs = net(inputstest);
errors = gsubtract(targetstest,outputs);
performance = perform(net,targetstest,outputs)
% View the Network
%view(net)
% Plots
% Uncomment these lines to enable various plots.
% figure, plotperform(tr)
% figure, plottrainstate(tr)
% figure, plotconfusion(targets,outputs)
% figure, ploterrhist(errors)
%evaluate performance
Y=net(inputstest);
plotconfusion(targetstest,Y);