-
Notifications
You must be signed in to change notification settings - Fork 2
/
Assignment_2_4_2.m
77 lines (60 loc) · 1.62 KB
/
Assignment_2_4_2.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
clc;
clear all;
close all;
data = xlsread('dataset.xlsx');
data(:,1:end-1) = (data(:,1:end-1)-mean(data(:,1:end-1)))./std(data(:,1:end-1));
X = data(:,1:end-1); %Inputs
Y = data(:,end); %Target outputs
for i=1:size(Y,1)
if Y(i)==0
btrainY(i,:)=[1,0];
else
btrainY(i,:)=[0,1];
end
end
for i=1:size(Y,1)
[~,l(:,i)]=max(btrainY(i,:));%index at which the maximum value of Y(i) occurs
end
c=cvpartition(l,'KFold',5);
for j=1:c.NumTestSets
trIdx=c.training(j);
teidx=c.test(j);
xtr=X(trIdx,:);
ytr=btrainY(trIdx,:);
xte=X(teidx,:);
yte=btrainY(teidx,:);
xtrain=xtr;
ytrain=ytr;
xtest=xte;
ytest=yte;
tic
NumberofHiddenNeurons=600;
NumberofTrainingData=size(xtrain,1);
NumberofTestingData=size(xtest,1);
NumberofInputNeurons=size(xtrain,2);
randommat=randn(NumberofInputNeurons+1,NumberofHiddenNeurons);
tempH=[ones(size(xtrain,1),1) xtrain]*randommat;
H=normpdf(tempH,mean(tempH),std(tempH));
[m,n]=size(H);
OutputWeight=pinv(H)*ytrain;
testH=[ones(size(xtest,1),1) xtest]*randommat;
Ht=normpdf(testH,mean(testH),std(testH));
yn=Ht*OutputWeight;
for i=1:size(xtest,1)
[~, lp(:,i)]=max(yn(i,:));
[~, lt(:,i)]=max(ytest(i,:));
end
[cmt,order]=confusionmat(lp,lt);
display(cmt);
IA=zeros(1,2);
OA=0;
for i=1:2
IA(i)=cmt(i,i)/sum(cmt(i,:));
OA=OA+cmt(i,i);
end
OA=OA/sum(cmt(:));
toc
display(IA);
display(OA);
toc
end