libsvm准确吗?

发布于 2024-09-19 06:47:17 字数 1380 浏览 3 评论 0原文

经过 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 返回的系数 a1a2a3 应该是在以下限制条件下尽可能大的 : a1 + a3 = a2 并且a1a2a3中的每一个都要求位于0和1之间(C的默认值)。

上面的模型文件给出的答案是

a1 = .412665...
a2 = .444410...
a3 = .031745...

但是只需将 a2 = a1 + a3 代入上面的大公式并确认两个偏导数都为零即可查看该解决方案是否正确(因为 < code>a1、a2a3 是 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 that
a1 + 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 技术交流群。

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

发布评论

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

评论(1

最佳男配角 2024-09-26 06:47:17

LibSVM 是一个使用非常广泛的库,我非常怀疑代码是否存在严重错误。也就是说,我认为有人足够偏执地实际检查它的正确性,这很好 - 干得好!

根据我下面给出的工作,该解决方案似乎是正确的。我的意思是它满足 KKT 条件 (15.29)。对偶的偏导数在解处消失也是事实。

这是我的工作...

x1 = (3,1,0)  x2 = (3,3,1)  x3 = (7,0,9)
y1 = -1       y2 = 1        y3 = -1

K = [10   12   21]
    [12   19   30]
    [21   30  130]

L_dual = a1 + a2 + a3 -5a1^2 + 12a1a2 - 21a1a3 - (19/2)a2^2 + 30a2a3 - 65a3^2)

a1 = 0.412  a2 = 0.4444  a3 = 0.0317

Checking KKT:
y1.f(x1) = y1 * (y1*a1*K(x1,x1) + y2*a2*K(x1,x2) + y3*a3*k(x1,x3) - rho)
         = rho + 10*a1 + 21*a3 - 12*a2
         ~= 1
(Similar for the x2 and x3)

Substituting a2 = a1 + a3 into L_dual:
L_dual = 2a1 + 2a3 - 2.5a1^2 + 2a1a3 - 44.5a3^2
dL/da1 = 2 - 5a1 + 2a3 = 0
dL/da3 = 2 + 2a1 - 89a3 = 0

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...

x1 = (3,1,0)  x2 = (3,3,1)  x3 = (7,0,9)
y1 = -1       y2 = 1        y3 = -1

K = [10   12   21]
    [12   19   30]
    [21   30  130]

L_dual = a1 + a2 + a3 -5a1^2 + 12a1a2 - 21a1a3 - (19/2)a2^2 + 30a2a3 - 65a3^2)

a1 = 0.412  a2 = 0.4444  a3 = 0.0317

Checking KKT:
y1.f(x1) = y1 * (y1*a1*K(x1,x1) + y2*a2*K(x1,x2) + y3*a3*k(x1,x3) - rho)
         = rho + 10*a1 + 21*a3 - 12*a2
         ~= 1
(Similar for the x2 and x3)

Substituting a2 = a1 + a3 into L_dual:
L_dual = 2a1 + 2a3 - 2.5a1^2 + 2a1a3 - 44.5a3^2
dL/da1 = 2 - 5a1 + 2a3 = 0
dL/da3 = 2 + 2a1 - 89a3 = 0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文