Question

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

Was it helpful?

Solution 3

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

OTHER TIPS

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.

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top