当前位置: 动力学知识库 > 问答 > 编程问答 >

How to disable logs of LibSVM weka library in java?

问题描述:

I am using LibSVM library on Weka 3.6 and experiencing similar problem as in here (for Java) and here (for Python)

The libSVM library generates a lot of logs simliar to this

optimization finished, #iter = 399

nu = 0.9503376170384973

obj = -124.54791151883072, rho = 0.0528133707297996

nSV = 257, nBSV = 97

I followed the solution using -q parameters by setting this parameter in my code:

LibSVM svm = new LibSVM();

String[] options = {"-q"};

svm.setOptions(options);

Although this solution seems to work in Python but I doesn't work in my Java code.

Another solution suggests using Log4j and disable some level of logs, however, I don't want to add another library to my code.

Now, I'm wondering is there any clean and simple solution to disable libSVM logs?

网友答案:

LibSVM library for Weka with FQN of "weka.classifiers.functions.LibSVM" is a wrapper around svm algorithm to create a common interface for Java programmers are using Weka API.

Inside "LibSVM.jar" there is another jar file which named "libsvm.jar" which is the main algorithm. Contrary to LibSVM which use common Java naming conventions, the naming convention inside "libsvm.jar" is different. Inside "libsvm" package there is a class named "svm". Because I had used "svm" as my variable name, the "svm" class was invisible.

After knowing that, I followed the instruction in here and changed the "svm" to "libsvm.svm" and this is the code which is working for me. In addition, I put this code in a static block of my code to have it for all my usages.

static{
    libsvm.svm.svm_set_print_string_function(new libsvm.svm_print_interface() {
        @Override
        public void print(String s) {
        } // Disables svm output
    });
}

Finally, I am using LibSVM without annoying logs.

分享给朋友:
您可能感兴趣的文章:
随机阅读: