Matlab libsvm svmpredict accuracy verbose

5.6k Views Asked by At

I have a question of an annoying fact. I'm using libsvm with matlab and I'am able to predict using:

predicted_label = svmpredict(Ylabel, Xlabel, model);

but it happen that every time I make a predictions appears this:

Accuracy = X% (y/n) (classification)

Which I find annoying because I am repeating this procedure a lot of times and also makes it slow because its displaying in screen.

I think what I want is to avoid that svmpredict being verbose.

Can anyone help me with this? Thanks in advance.

-Jessica

3

There are 3 best solutions below

1
On BEST ANSWER

If you are using matlab, just find the line of code that is displaying this information (usually using 'disp', 'sprintf', or 'fprintf') and comment it out using the commenting operator %.

example:

disp(['Accuracy= ' num2str(x)]);

change it to:

% disp(['Accuracy= ' num2str(x)]);

If you are using the main libsvm library then you need to modify it before making. 1- Open the file 'svmpredict.c'

2- find this line of code:

info("Accuracy = %g%% (%d/%d) (classification)\n",
(double)correct/total*100,correct,total);

3- just comment it out using // operator

4- save and close the file

5- make the project

2
On

I found a much better approach than editing the source code of the c library was to use matlabs evalc which places any output to the first output argument.

[~ predicted_label] = evalc('svmpredict(Ylabel, Xlabel, model)');

Because the string to be evaluated is fixed should be no performance decrease.

2
On
svmpredict(Ylabel, Xlabel, model, '-q');

From the manual:

Usage: [predicted_label, accuracy, decision_values/prob_estimates] = svmpredict(testing_label_vector, testing_instance_matrix, model, 'libsvm_options')
       [predicted_label] = svmpredict(testing_label_vector, testing_instance_matrix, model, 'libsvm_options')
Parameters:
  model: SVM model structure from svmtrain.
  libsvm_options:
    -b probability_estimates: whether to predict probability estimates, 0 or 1 (default 0); one-class SVM not supported yet
    -q : quiet mode (no outputs)