%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % SVM tutorials % Z. Li, 2009.02.08 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear; x = [ 2.5240 2.2263 2.9271 2.9319 2.7735 3.2238 3.8484 3.8321 4.4242 4.7080 3.7524 4.6350 4.5585 3.7105 5.2879 5.3163 5.0384 4.6107 5.9597 5.8759 ]; y =[ 0.8925 4.3431 1.1996 4.8297 1.0653 5.2920 1.5259 5.4380 1.5259 6.2409 1.2188 6.8491 1.7179 7.0438 1.9290 6.2895 2.0058 7.7737 1.7370 8.2847 ]; if (1) figure; hold on; axis([1 100 1 100]); nx = 24; ny = 24; fprintf('\n input x points...'); for k=1:nx [x1, x2]=ginput(1); plot(x1, x2, '+r'); x(k, :)=[x1, x2]; end fprintf('\n input y points...'); for k=1:ny [x1, x2]=ginput(1); plot(x1, x2, '.k'); y(k, :)=[x1, x2]; end save svm_test_data.mat x y; else %load svm_test_data_linear.mat; load svm_test_data.mat; hold on; grid on; axis([1 100 1 100]); plot(x(:,1), x(:,2), '+r'); plot(y(:,1), y(:,2), '.k'); end [nx, d]=size(x); [ny,d]=size(y); data(1:nx,:)=x; labels(1:nx, 1) = 'x'; data(nx+1:nx+ny,:)=y; labels(nx+1:nx+ny, 1) = 'y'; if (1) svmStruct = svmtrain(data, labels, 'showplot',true); else svmStruct = svmtrain(data, labels, 'kernel_function', 'quadratic','showplot',true); end % test svm nTest = 3; for k=1:nTest [x1, x2] = ginput(1); hold on; grid on; plot(x1, x2, '*m'); test(k, :) = [x1, x2]; end classes = svmclassify(svmStruct, test,'showplot',true); return;