在libsvm(python)中抑制输出

4
我正在使用Python中的libsvm(svmutils)进行分类任务。分类器是精确的。然而,我得到的输出如下:
*
optimization finished, #iter = 75
nu = 0.000021
obj = -0.024330, rho = 0.563710
nSV = 26, nBSV = 0
Total nSV = 26
*
optimization finished, #iter = 66
nu = 0.000030
obj = -0.035536, rho = -0.500676
nSV = 21, nBSV = 0
Total nSV = 21
*
optimization finished, #iter = 78
nu = 0.000029
obj = -0.033921, rho = -0.543311
nSV = 23, nBSV = 0
Total nSV = 23
*
optimization finished, #iter = 90
nu = 0.000030
obj = -0.035333, rho = -0.634721
nSV = 23, nBSV = 0
Total nSV = 23
Accuracy = 0% (0/1) (classification)
Accuracy = 0% (0/1) (classification)
Accuracy = 0% (0/1) (classification)
Accuracy = 0% (0/1) (classification)

有没有办法可以禁止出现这个对话框?分类器完全正常,只是我好奇。此外,“准确度”代表什么?为什么在我的情况下为0%?(数据在80个维度中不重叠。总共4个类别。我也已经适当地进行了归一化。)
3个回答

6

使用-q参数选项。

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')

1

为了抑制训练和预测输出,你需要将 has2k1(用于抑制训练输出)和 vonPetrushev(用于抑制预测输出)提供的解决方案组合起来。

不幸的是,你不能像下面这样做:

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

因为使用当前的Python接口会出现以下错误:
  File "/home/jbbrown/local_bin/pyLibSVM/pyLibSVM/svmutil.py", line 193, in svm_predict
    raise ValueError("Wrong options")
  ValueError: Wrong options

1

这可以工作:

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

此外,在分类问题中,准确率是使用训练模型对测试/交叉验证集正确预测的项目所占的部分(百分比)。

实际上,我有一些训练数据,分别属于4个类,每个类别都有一个80维的特征向量和4个one-vs-rest分类器来测试单个测试点。在这种情况下,是否通过类似于“如果测试点在训练期间已经标记,则交叉验证成功并且准确度为100%,否则交叉验证失败并且准确度为0”的方式来计算准确率?(在此方法中,由于测试数据仅为单个点,因此仅为0或100%)我理解得对吗?感谢您的答复。 - Nihar Sarangi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接