抑制 libsvm 中的输出 (python)

发布于 2024-12-18 08:50:10 字数 824 浏览 2 评论 0原文

我正在使用 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个类。我也对其进行了适当的归一化。)

I am using libsvm (svmutils) from python for a classification task. The classifier is exact. However, I am getting output like this:

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

Is there any way I can suppress this dialog? The classifier serves perfectly fine, I am just curious. Also, what does the "Accuracy" stand for? And why this is 0% in my case? (The data is non-overlapping in 80 dimensions. Total 4 classes. I have also normalized it properly.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

原来是傀儡 2024-12-25 08:50:10

使用 -q 参数选项

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

或者

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

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')
驱逐舰岛风号 2024-12-25 08:50:10

这可以工作:

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

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

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.

痕至 2024-12-25 08:50:10

要抑制训练和预测输出,您需要结合 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文