Suppressing the output in libsvm (python)

浪子不回头ぞ 提交于 2019-12-01 06:49:21

Use the -q parameter option

import svmutil
param = svmutil.svm_parameter('-q')
...

or

import svmutil
x = [[0.2, 0.1], [0.7, 0.6]]
y = [0, 1]
svmutil.svm_train(y, x, '-q')
vonPetrushev

This can work:

import sys
from StringIO import StringIO

# back up your standard output
bkp_stdout = sys.stdout

# replace standard output with dummy stream
sys.stdout = StringIO()
print 1  # here you should put you call (classification)

#restore standard output for further use
sys.stdout = bkp_stdout
print 2

Also, in classification problems, accuracy is the part (percentage) of correctly predicted items from your testing / cross-validation set using the trained model.

To suppress both training and prediction output, you will need to combine the solutions provided by has2k1 (for suppressing training output) and vonPetrushev (for suppressing prediction output).

Unfortunately, you cannot do something like the following:

# Test matrix built, execute prediction.
paramString = "" if useVerbosity else " -q "
predLabels, predAccuracy, predDiscriminants = \
 svmutil.svm_predict( targetLabels, testData, svModel.representation, paramString )

Because with the current python interface you will get the following error:

  File "/home/jbbrown/local_bin/pyLibSVM/pyLibSVM/svmutil.py", line 193, in svm_predict
    raise ValueError("Wrong options")
  ValueError: Wrong options
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!