I am using cross validation in svmtrain in LIBSVM. How can I make it stop printing the "Cross Validation Accuracy" in the consol? Thank you
Asked
Active
Viewed 568 times
1
-
3This question appears to be off-topic because it is not about programming. Perhaps [Super User](http://superuser.com/) would be a better place to ask. – jww Jun 18 '14 at 04:03
-
@jww It is about programming though. He has to change the source code in order to do this – Pedrom Jun 23 '14 at 12:32
-
@Pedrom - you should nominate for reopen. – jww Jun 23 '14 at 12:43
1 Answers
2
You would have to change the code for that because there is not option to do cross-validation in silent mode.
You didn't specified how you are using libsvm so assuming that you are in C, this is the function you must to change:
void do_cross_validation()
{
int i;
int total_correct = 0;
double total_error = 0;
double sumv = 0, sumy = 0, sumvv = 0, sumyy = 0, sumvy = 0;
double *target = Malloc(double,prob.l);
svm_cross_validation(&prob,¶m,nr_fold,target);
if(param.svm_type == EPSILON_SVR ||
param.svm_type == NU_SVR)
{
for(i=0;i<prob.l;i++)
{
double y = prob.y[i];
double v = target[i];
total_error += (v-y)*(v-y);
sumv += v;
sumy += y;
sumvv += v*v;
sumyy += y*y;
sumvy += v*y;
}
printf("Cross Validation Mean squared error = %g\n",total_error/prob.l);
printf("Cross Validation Squared correlation coefficient = %g\n",
((prob.l*sumvy-sumv*sumy)*(prob.l*sumvy-sumv*sumy))/
((prob.l*sumvv-sumv*sumv)*(prob.l*sumyy-sumy*sumy))
);
}
else
{
for(i=0;i<prob.l;i++)
if(target[i] == prob.y[i])
++total_correct;
printf("Cross Validation Accuracy = %g%%\n",100.0*total_correct/prob.l);
}
free(target);
}
EDIT: This you just told me that you are using matlab, you will need to remove the mexPrintf statement from svmtrain.c:100 and recompile the interface within Matlab.

Pedrom
- 3,823
- 23
- 26
-
I am using in matlab by using this line cv_acc(i) = svmtrain(labels, data,sprintf('-t 2 -c %f -g %f -v %d ', 2^C(i), 2^gamma(i), folds)); end .Cross validation is done automatically by adding -v and variable fold which specify the number of validation folds. – user3656367 Jun 06 '14 at 07:31
-
@user3656367 Then I think you would need to make the changes on the C code and recompile the matlab interface – Pedrom Jun 06 '14 at 18:17
-
Yes the changes must be done in the C file.simply commenting the print command. – user3656367 Jun 23 '14 at 11:46