libsvm准确吗?
经过 StompChicken 的更正(我错误地计算了一个点积,呃!),答案似乎是肯定的。此后,我使用预先计算的内核测试了相同的问题,并得到了相同的正确结果。如果您使用 libsvm StompChickens ,清晰、有组织的计算是一个非常好的检查。
原始问题: 我即将开始在 libSVM 中使用预计算内核。我注意到了 Vlad 对一个问题的回答,我认为确认 libsvm 是明智的给出了正确答案。我从非预先计算的内核开始,只是一个简单的线性内核,在 3 维空间中具有 2 个类和三个数据点。 数据
1 1:3 2:1 3:0
2 1:3 2:3 3:1
1 1:7 3:9
我使用了通过调用 svm-train -s 0 - t 0 生成的
svm_type c_svc
kernel_type linear
nr_class 2
total_sv 3
rho -1.53951
label 1 2
nr_sv 2 1
SV
0.4126650675419768 1:3 2:1 3:0
0.03174528241667363 1:7 3:9
-0.4444103499586504 1:3 2:3 3:1
模型文件包含但是,当我手动计算解决方案时,这不是我得到的。有谁知道 libsvm 是否遇到错误,或者有人可以比较笔记并看看他们是否得到与 libsvm 相同的东西吗?
值
a1 + a2 + a3 - 5*a1*a1 + 12*a1*a2 - 21*a1*a3 - 19*a2*a2/2 + 21*a2*a3 - 65*a3*a3
libsvm 返回的系数 a1
、a2
、a3
应该是在以下限制条件下尽可能大的 : a1 + a3 = a2
并且a1
、a2
、a3
中的每一个都要求位于0和1之间(C的默认值)。
上面的模型文件给出的答案是
a1 = .412665...
a2 = .444410...
a3 = .031745...
但是只需将 a2 = a1 + a3
代入上面的大公式并确认两个偏导数都为零即可查看该解决方案是否正确(因为 < code>a1、a2
、a3
是 0 或 1),但它们不为零。
我做错了什么,还是 libsvm 给出了不好的结果? (我希望我做错了什么。)
With StompChicken's corrections (I miscomputed one dot product, ugh!) the answer appears to be yes. I have since tested the same problem using a precomputed kernel with the same correct results. If you are using libsvm StompChickens clear, organized computations are a very nice check.
Original Question:
I am about to start using precomputed kernels in libSVM. I had noticed
Vlad's answer to a question and I thought it would be wise to confirm that libsvm gave correct answers. I started with non-precomputed kernels, just a simple linear kernel with 2 classes and three data points in 3 dimensional space. I used the data
1 1:3 2:1 3:0
2 1:3 2:3 3:1
1 1:7 3:9
The model file generated by a call to svm-train -s 0 - t 0
contains
svm_type c_svc
kernel_type linear
nr_class 2
total_sv 3
rho -1.53951
label 1 2
nr_sv 2 1
SV
0.4126650675419768 1:3 2:1 3:0
0.03174528241667363 1:7 3:9
-0.4444103499586504 1:3 2:3 3:1
However when I compute the solution by hand that is not what I get. Does anyone know whether libsvm suffers from errors or can anyone compare notes and see whether they get the same thing libsvm does?
The coefficients a1
, a2
, a3
returned by libsvm are should be the values that make
a1 + a2 + a3 - 5*a1*a1 + 12*a1*a2 - 21*a1*a3 - 19*a2*a2/2 + 21*a2*a3 - 65*a3*a3
as large as possible with the restrictions thata1 + a3 = a2
and each of a1
, a2
, a3
is required to lie between 0 and 1 (the default value of C).
The above model file says the answer is
a1 = .412665...
a2 = .444410...
a3 = .031745...
But one just has to substitute a2 = a1 + a3
into the big formula above and confirm both partial derivatives are zero to see if this solution is correct (since none of a1
,a2
,a3
is 0 or 1) but they are not zero.
Am I doing something wrong, or is libsvm giving bad results? (I am hoping I am doing something wrong.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LibSVM 是一个使用非常广泛的库,我非常怀疑代码是否存在严重错误。也就是说,我认为有人足够偏执地实际检查它的正确性,这很好 - 干得好!
根据我下面给出的工作,该解决方案似乎是正确的。我的意思是它满足 KKT 条件 (15.29)。对偶的偏导数在解处消失也是事实。
这是我的工作...
LibSVM is a very widely used library and I highly doubt anything is drastically wrong with the code. That said, I think it's great that there are people who are paranoid enough to actually check it for correctness - well done!
The solution seems correct according to the working that I give below. What I mean by that is it satisfies the KKT conditions (15.29). It also true that the partial derivatives of the dual vanish at the solution.
Here's my working...