Code
This example will show us how is process the Iris data base on the algorithm of Support Vectore Machine.
% --- Executes on button press in Entrenar.
function Entrenar_Callback(hObject, eventdata, handles)
Iris=load ('irisdataset'); % Load the Iris data
global maquina1;global maquina2;global maquina3; %We define three machine for the SVM
Condicion=0;
kernel = get(handles.Kernel,'Value'); %We get the value of the picker and map it with the kernel that we want to use.
switch kernel
case 1
set(handles.Efectividad, 'String', 'Elige una opci?n valida');
Condicion=1;
case 2
opcKernel = 'linear';
case 3
opcKernel = 'quadratic';
case 4
opcKernel = 'polynomial';
case 5
opcKernel = 'rbf';
case 6
opcKernel = 'mlp';
end
if Condicion==0 %We define in each machine each type of Flower (Setosa, Versicolor, Virginia)
maquina1 = svmtrain(Iris.Datos',Iris.setosa, 'kernel_func', opcKernel);
maquina2 = svmtrain(Iris.Datos',Iris.versicolor, 'kernel_func', opcKernel);
maquina3 = svmtrain(Iris.Datos',Iris.virginica, 'kernel_func', opcKernel);
set(handles.Efectividad,'String','La efectividad es:');
correcto = 0;incorrectos = 0;
for i = 1:150
classe(1)= svmclassify(maquina1, Iris.Datos(i,:)); %We use the function of svmclassify for each class
classe(2) = svmclassify(maquina2, Iris.Datos(i,:));
classe(3) = svmclassify(maquina3, Iris.Datos(i,:));
if classe == Iris.salida(i,:)
correcto = correcto + 1;
else
incorrectos = incorrectos + 1;
end
end
D1=get(handles.G1,'Value');
%Print the data.
svmtrain(Iris.Datos(1:100,D1-1:D1)',Iris.setosa(1:100,1),'kernel_func', opcKernel, 'ShowPlot',true);
hold on
svmtrain(Iris.Datos(51:150,D1-1:D1)',Iris.versicolor(51:150,1),'kernel_func', opcKernel, 'ShowPlot',true);
hold off
porcentaje = (correcto*100)/150; %We print the error that we get with that combination
set(handles.Efectividad1, 'String', sprintf('%.4f %d', porcentaje));
end
Last updated
Was this helpful?