% Real and predicted classifications figure of test set % The figure shows that only one sample was classified improperly
figure; hold on; plot(test_wine_labels,'o'); plot(predict_label,'r*'); xlabel('Test Set Sample','FontSize',12); ylabel('Label','FontSize',12); legend('Real','Predicted'); title('Classifications Figure of Test Set','FontSize',12); grid on;
Classifier Parameters Optimization
1 2 3 4 5 6 7
% Roughly select: c & g range in 2^(-10),2^(-9),...,2^(10) [bestacc,bestc,bestg] = SVMcgForClass(train_wine_labels,train_wine_data,-10,10,-10,10);
% Print the result of rough selection disp('Printing the result of rough selection'); str = sprintf( 'Best Cross Validation Accuracy = %g%% Best c = %g Best g = %g',bestacc,bestc,bestg); disp(str);
Result:
Printing the result of rough selection
Best Cross Validation Accuracy = 97.7528% Best c = 1.31951 Best g = 1.31951
1 2 3 4 5 6
% Precisely: c range in 2^(-2),2^(-1.5),...,2^(4), g range in 2^(-4),2^(-3.5),...,2^(4), [bestacc,bestc,bestg] = SVMcgForClass(train_wine_labels,train_wine_data,-2,4,-4,4,3,0.5,0.5,0.9); % Print the result of precise selection: disp('Printing the result of precise selection'); str = sprintf( 'Best Cross Validation Accuracy = %g%% Best c = %g Best g = %g',bestacc,bestc,bestg); disp(str);
Result:
Printing the result of precise selection
Best Cross Validation Accuracy = 97.7528% Best c = 0.353553 Best g = 1
Accuracy is lower than c = 2, g = 1’s, WHY?
P.S. SVMcgForClass is a function written by faruto.