LVQ umumnya untuk proses 2 Class..
dalam praktek kali ini kita akan mencoba LVQ untuk mengklasifikasikan 6 class berbeda
yaitu kelas 1,2,3,4,5,6
atau secara biner
c1=[1 0 0 0 0 0]';
c2=[0 1 0 0 0 0]';
c3=[0 0 1 0 0 0]';
c4=[0 0 0 1 0 0]';
c5=[0 0 0 0 1 0]';
c6=[0 0 0 0 0 1]';
Secara default data iris system matlab terdiri dari 3 class yaitu kelas 1,2,3
c1=1 0 0
c2=0 1 0
c3=0 0 1
karena kita akan menguji untuk 6 class berbeda...maka kita butuh bantuan algoritma lain untuk generate klasifikasinya
misal menggunakan Kmeans....sehingga dataIris sekarang menjadi 6 class berbeda
dengan LVQ lalu di uji....dan dibandingkan hasil prosesnya thd data class awalnya
dan di dapat akurasi 93%
>> clear
>> [x,t] = iris_dataset;
>> x
x =
Columns 1 through 14
5.1000 4.9000 4.7000 4.6000 5.0000 5.4000 4.6000 5.0000 4.4000 4.9000 5.4000 4.8000 4.8000 4.3000
3.5000 3.0000 3.2000 3.1000 3.6000 3.9000 3.4000 3.4000 2.9000 3.1000 3.7000 3.4000 3.0000 3.0000
1.4000 1.4000 1.3000 1.5000 1.4000 1.7000 1.4000 1.5000 1.4000 1.5000 1.5000 1.6000 1.4000 1.1000
0.2000 0.2000 0.2000 0.2000 0.2000 0.4000 0.3000 0.2000 0.2000 0.1000 0.2000 0.2000 0.1000 0.1000
Columns 15 through 28
5.8000 5.7000 5.4000 5.1000 5.7000 5.1000 5.4000 5.1000 4.6000 5.1000 4.8000 5.0000 5.0000 5.2000
4.0000 4.4000 3.9000 3.5000 3.8000 3.8000 3.4000 3.7000 3.6000 3.3000 3.4000 3.0000 3.4000 3.5000
1.2000 1.5000 1.3000 1.4000 1.7000 1.5000 1.7000 1.5000 1.0000 1.7000 1.9000 1.6000 1.6000 1.5000
0.2000 0.4000 0.4000 0.3000 0.3000 0.3000 0.2000 0.4000 0.2000 0.5000 0.2000 0.2000 0.4000 0.2000
Columns 29 through 42
5.2000 4.7000 4.8000 5.4000 5.2000 5.5000 4.9000 5.0000 5.5000 4.9000 4.4000 5.1000 5.0000 4.5000
3.4000 3.2000 3.1000 3.4000 4.1000 4.2000 3.1000 3.2000 3.5000 3.1000 3.0000 3.4000 3.5000 2.3000
1.4000 1.6000 1.6000 1.5000 1.5000 1.4000 1.5000 1.2000 1.3000 1.5000 1.3000 1.5000 1.3000 1.3000
0.2000 0.2000 0.2000 0.4000 0.1000 0.2000 0.1000 0.2000 0.2000 0.1000 0.2000 0.2000 0.3000 0.3000
Columns 43 through 56
4.4000 5.0000 5.1000 4.8000 5.1000 4.6000 5.3000 5.0000 7.0000 6.4000 6.9000 5.5000 6.5000 5.7000
3.2000 3.5000 3.8000 3.0000 3.8000 3.2000 3.7000 3.3000 3.2000 3.2000 3.1000 2.3000 2.8000 2.8000
1.3000 1.6000 1.9000 1.4000 1.6000 1.4000 1.5000 1.4000 4.7000 4.5000 4.9000 4.0000 4.6000 4.5000
0.2000 0.6000 0.4000 0.3000 0.2000 0.2000 0.2000 0.2000 1.4000 1.5000 1.5000 1.3000 1.5000 1.3000
Columns 57 through 70
6.3000 4.9000 6.6000 5.2000 5.0000 5.9000 6.0000 6.1000 5.6000 6.7000 5.6000 5.8000 6.2000 5.6000
3.3000 2.4000 2.9000 2.7000 2.0000 3.0000 2.2000 2.9000 2.9000 3.1000 3.0000 2.7000 2.2000 2.5000
4.7000 3.3000 4.6000 3.9000 3.5000 4.2000 4.0000 4.7000 3.6000 4.4000 4.5000 4.1000 4.5000 3.9000
1.6000 1.0000 1.3000 1.4000 1.0000 1.5000 1.0000 1.4000 1.3000 1.4000 1.5000 1.0000 1.5000 1.1000
Columns 71 through 84
5.9000 6.1000 6.3000 6.1000 6.4000 6.6000 6.8000 6.7000 6.0000 5.7000 5.5000 5.5000 5.8000 6.0000
3.2000 2.8000 2.5000 2.8000 2.9000 3.0000 2.8000 3.0000 2.9000 2.6000 2.4000 2.4000 2.7000 2.7000
4.8000 4.0000 4.9000 4.7000 4.3000 4.4000 4.8000 5.0000 4.5000 3.5000 3.8000 3.7000 3.9000 5.1000
1.8000 1.3000 1.5000 1.2000 1.3000 1.4000 1.4000 1.7000 1.5000 1.0000 1.1000 1.0000 1.2000 1.6000
Columns 85 through 98
5.4000 6.0000 6.7000 6.3000 5.6000 5.5000 5.5000 6.1000 5.8000 5.0000 5.6000 5.7000 5.7000 6.2000
3.0000 3.4000 3.1000 2.3000 3.0000 2.5000 2.6000 3.0000 2.6000 2.3000 2.7000 3.0000 2.9000 2.9000
4.5000 4.5000 4.7000 4.4000 4.1000 4.0000 4.4000 4.6000 4.0000 3.3000 4.2000 4.2000 4.2000 4.3000
1.5000 1.6000 1.5000 1.3000 1.3000 1.3000 1.2000 1.4000 1.2000 1.0000 1.3000 1.2000 1.3000 1.3000
Columns 99 through 112
5.1000 5.7000 6.3000 5.8000 7.1000 6.3000 6.5000 7.6000 4.9000 7.3000 6.7000 7.2000 6.5000 6.4000
2.5000 2.8000 3.3000 2.7000 3.0000 2.9000 3.0000 3.0000 2.5000 2.9000 2.5000 3.6000 3.2000 2.7000
3.0000 4.1000 6.0000 5.1000 5.9000 5.6000 5.8000 6.6000 4.5000 6.3000 5.8000 6.1000 5.1000 5.3000
1.1000 1.3000 2.5000 1.9000 2.1000 1.8000 2.2000 2.1000 1.7000 1.8000 1.8000 2.5000 2.0000 1.9000
Columns 113 through 126
6.8000 5.7000 5.8000 6.4000 6.5000 7.7000 7.7000 6.0000 6.9000 5.6000 7.7000 6.3000 6.7000 7.2000
3.0000 2.5000 2.8000 3.2000 3.0000 3.8000 2.6000 2.2000 3.2000 2.8000 2.8000 2.7000 3.3000 3.2000
5.5000 5.0000 5.1000 5.3000 5.5000 6.7000 6.9000 5.0000 5.7000 4.9000 6.7000 4.9000 5.7000 6.0000
2.1000 2.0000 2.4000 2.3000 1.8000 2.2000 2.3000 1.5000 2.3000 2.0000 2.0000 1.8000 2.1000 1.8000
Columns 127 through 140
6.2000 6.1000 6.4000 7.2000 7.4000 7.9000 6.4000 6.3000 6.1000 7.7000 6.3000 6.4000 6.0000 6.9000
2.8000 3.0000 2.8000 3.0000 2.8000 3.8000 2.8000 2.8000 2.6000 3.0000 3.4000 3.1000 3.0000 3.1000
4.8000 4.9000 5.6000 5.8000 6.1000 6.4000 5.6000 5.1000 5.6000 6.1000 5.6000 5.5000 4.8000 5.4000
1.8000 1.8000 2.1000 1.6000 1.9000 2.0000 2.2000 1.5000 1.4000 2.3000 2.4000 1.8000 1.8000 2.1000
Columns 141 through 150
6.7000 6.9000 5.8000 6.8000 6.7000 6.7000 6.3000 6.5000 6.2000 5.9000
3.1000 3.1000 2.7000 3.2000 3.3000 3.0000 2.5000 3.0000 3.4000 3.0000
5.6000 5.1000 5.1000 5.9000 5.7000 5.2000 5.0000 5.2000 5.4000 5.1000
2.4000 2.3000 1.9000 2.3000 2.5000 2.3000 1.9000 2.0000 2.3000 1.8000
>> t
t =
Columns 1 through 23
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 24 through 46
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 47 through 69
1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 70 through 92
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Columns 93 through 115
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Columns 116 through 138
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Columns 139 through 150
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1
>> idx4 = kmeans(x',6);
>> idx4'
ans =
Columns 1 through 23
4 3 3 3 4 4 3 3 3 3 4 3 3 3 4 4 4 4 4 4 4 4 3
Columns 24 through 46
4 3 3 4 4 4 3 3 4 4 4 3 3 4 3 3 4 4 1 3 4 4 3
Columns 47 through 69
4 3 4 3 2 2 2 6 2 6 2 6 2 6 6 6 6 2 6 2 2 6 2
Columns 70 through 92
6 2 6 2 2 2 2 2 2 2 6 6 6 6 2 6 2 2 2 6 6 6 2
Columns 93 through 115
6 6 6 6 6 2 6 6 5 2 5 5 5 5 6 5 5 5 2 2 5 2 2
Columns 116 through 138
5 5 5 5 2 5 2 5 2 5 5 2 2 5 5 5 5 5 2 2 5 5 5
Columns 139 through 150
2 5 5 5 2 5 5 5 2 2 5 2
>> N=size(x,2)
N =
150
>>
c1=[1 0 0 0 0 0]';
c2=[0 1 0 0 0 0]';
c3=[0 0 1 0 0 0]';
c4=[0 0 0 1 0 0]';
c5=[0 0 0 0 1 0]';
c6=[0 0 0 0 0 1]';
P=[];
for i= 1:N
if idx4(i)==1
P(:,i)=c1;
elseif idx4(i)==2
P(:,i)=c2;
elseif idx4(i)==3
P(:,i)=c3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through 46
4 3 3 4 4 4 3 3 4 4 4 3 3 4 3 3 4 4 1 3 4 4 3
Columns 47 through 69
4 3 4 3 2 2 2 6 2 6 2 6 2 6 6 6 6 2 6 2 2 6 2
Columns 70 through 92
6 2 6 2 2 2 2 2 2 2 6 6 6 6 2 6 2 2 2 6 6 6 2
Columns 93 through 115
6 6 6 6 6 2 6 6 5 2 5 5 5 5 6 5 5 5 2 2 5 2 2
Columns 116 through 138
5 5 5 5 2 5 2 5 2 5 5 2 2 5 5 5 5 5 2 2 5 5 5
Columns 139 through 150
2 5 5 5 2 5 5 5 2 2 5 2
classesout =
"Akurasi " "0.96667" " %"
>>
>>