📄 matlab interface for libsvm.htm
字号:
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A
name=f402><STRONG>问:关于模型文件,您能否解释的更详细一点?</STRONG></A><BR></P>
<P>在参数后面,每一条线代表一个支持向量。 支持向量按照先列出的标签列出(即类标签列表中,第一类的支持向量首先分组,然后依次类推) </P>
<P>如果k是类别的总数,那么每个支持向量的前面就有k-1个y*alpha系数,其中alpha代表如下二分类问题的对偶解:<BR>1 vs j, 2
vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k <BR>并且在前j-1个系数中,y=+1,
其余的k-j个系数中y=-1.例如,对于4分类问题,文件看起来结构如下: </P><PRE>+-+-+-+--------------------+
|1|1|1| |
|v|v|v| 类别1的支持向量 |
|2|3|4| |
+-+-+-+--------------------+
|1|2|2| |
|v|v|v| 类别2的支持向量 |
|2|3|4| |
+-+-+-+--------------------+
|1|2|3| |
|v|v|v| 类别3的支持向量 |
|3|3|4| |
+-+-+-+--------------------+
|1|2|3| |
|v|v|v| 类别4的支持向量 |
|4|4|4| |
+-+-+-+--------------------+
</PRE>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f403><STRONG>问:
在缓缓存中,是否可以用浮点型或者双精度型来存储数据?</STRONG></A> <BR></P>
<P>当你在缓存中存入更多的数据时,我们默认的是浮点型.一般情况下,这样就很好了,但是对于少数困难的情况(如C非常非常大)解将是巨大的数字。这时,仅用浮点型,数值的精度可能就不够了。
</P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A
name=f404><STRONG>问:怎样选择核函数?</STRONG></A> <BR></P>
<P>通常我们建议你首先采用RBF核函数。Keerthi 和 Lin 的最近的研究(<A
href="http://www.csie.ntu.edu.tw/~cjlin/papers/limit.ps.gz"> 下载论文</A>)
表明如果模型选择RBF的话,就没有必要再考虑线性核函数了。采用sigmoid核函数的矩阵不一定会正有界,而且通常它的准确性也不如RBF(可参见Lin和Lin的论文<A
href="http://www.csie.ntu.edu.tw/~cjlin/papers/tanh.pdf"> 此处下载</A>).
多项式核函数还不错,但是如果度数很高的话,数值困难就会发生(考虑到(<1)的d次幂会趋向0,(>1)的d次幂会趋向无穷) </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f405><STRONG>问:
libsvm是否可以用来专门处理线性SVM?D</STRONG></A> <BR></P>
<P>不是的,目前libsvm用同样的方法处理线性/非线性SVMs. 注意:如果采用线性核函数,一些技巧可能会节省训练/检验的时间。
因此libsvm对线性SVM并不时特别有效,尤其是采用很大的C的问题,这些问题数据的数值比其属性值要大得多。你可以: </P>
<UL>
<LI>仅用很大的C.下面的论文表明了:当C大于一个确定的阀值以后,判决函数是相同的。
<P><A href="http://guppy.mpe.nus.edu.sg/~mpessk/">S. S. Keerthi</A> and
<STRONG>C.-J. Lin</STRONG>. <A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/papers/limit.ps.gz">Asymptotic
behaviors of support vector machines with Gaussian kernel </A>. <EM><A
href="http://mitpress.mit.edu/journal-home.tcl?issn=08997667">Neural
Computation</A></EM>, 15(2003), 1667-1689. </P>
<LI>尝试用<A href="http://www.csie.ntu.edu.tw/~cjlin/bsvm">bsvm</A>,
它有个对解决线性SVMs很有效的方法.你可以在下面的研究中找到更详细的内容:
<P>K.-M. Chung, W.-C. Kao, T. Sun, and C.-J. Lin. <A
href="http://www.csie.ntu.edu.tw/~cjlin/papers/linear.pdf">Decomposition
Methods for Linear Support Vector Machines. </A><EM><A
href="http://mitpress.mit.edu/journal-home.tcl?issn=08997667">Neural
Computation</A></EM>, 16(2004), 1689-1704. </P></LI></UL>
<P>另外,你并没必要一定要解决线性SVMs.你可以参考前面有关如何选取核函数的问题。 </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f406><STRONG>问:
自由支持向量特别大,我该怎么办?</STRONG></A> <BR></P>
<P>当数据过拟和时,这种情况会经常发生.
如果数据的属性值范围特别大,你可以尝试调整它们的范围。这样合适参数的域可能会很大。注意:libsvm里包含有数据调整程序的,即svm_scale.
</P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f407><STRONG>问:
我是否可以用同样的方法来调整训练数据和检验数据的范围?</STRONG></A> <BR></P>
<P>是的, 可以按照以下方法: <BR>svm-scale -s scaling_parameters train_data >
scaled_train_data <BR>svm-scale -r scaling_parameters test_data >
scaled_test_data </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A
name=f408><STRONG>问:将属性值限制到[0,1],是否比限制到 [-1,1]有很大的不同?</STRONG></A>
<BR></P>
<P>对于线性规划方法,如果采用可RBF核函数并进行了参数的选择,两者是没什么不同的。假设Mi和mi分别代表第i个属性的最大值和最小值.规划到[0,1]即:
</P><PRE> x'=(x-mi)/(Mi-mi)
</PRE>
<P>对于[-1 1]: </P><PRE> x''=2(x-mi)/(Mi-mi)-1.
</PRE>
<P>在RBF核函数中: </P><PRE> x'-y'=(x-y)/(Mi-mi), x''-y''=2(x-y)/(Mi-mi).
</PRE>
<P>因此在[0,1]数据规划中用(C,g),和[-1 1]数据规划中用(C,g/2)是一样的。 </P>
<P>尽管性能相同,但是计算机时间可能不同。对于有许多零入口的数据, [0,1]规划保持了输入数据的稀疏特性,因此可能会节省计算时间。 </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f409><STRONG>问:
预测准确率很低,应该如何改进?</STRONG></A><BR></P>
<P>可以用python目下的grid.py来寻找合适的参数,grid.py是一个用来选择模型参数的工具。关于模型选择的重要性,你可以参考我的谈话:
<A href="http://www.csie.ntu.edu.tw/~cjlin/talks/freiburg.pdf">A practical
guide to support vector classification </A></P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f410><STRONG>问:
我的数据是不平衡的,libsvm能解决这样的问题吗?</STRONG></A><BR></P>
<P>可以。libsvm有一个-wi选项。例如,你用: </P>
<P>svm-train -s 0 -c 10 -w1 1 -w-1 5 data_file </P>
<P>则对类别“-1”的惩罚就较大。注意-w选项仅用在C-SVC中。 </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f411><STRONG>问:
nu-SVC和C-SVC有什么不同之处?</STRONG></A>
<BR>除了参数不同外,两者基本是一样的。C-SVC中,C的范围是0到无穷,nu-SVC中C的范围是[0 1]。
nu一个很好的特性是:它与支持向量的比率和训练误差的比率相关。 </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f412><STRONG>问:
程序一直运行,但却没有输出,应该怎么办?</STRONG></A><BR></P>
<P>你最好检查一下数据. 每一个训练/学习的数据都必须在一行,不可以分开。此外,你必须删除空行。 </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f413><STRONG>问:
程序一直运行(有输出,比如许多点)。应该怎么办?</STRONG></A><BR></P>
<P>从理论上讲,如果核矩阵式半正定的,libsvm可以保证收敛。2.4以后版本的libsvm还可以处理非半正定矩阵核,比如sigmoid(tanh)核。这样看来,你处理的情况是病态情况(比如参数过大或过小),这样机会发生数值困难。
</P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A name=f414><STRONG>问:
训练时间太长,应该怎么办?</STRONG></A><BR></P>
<P>对于大型问题,请确保有足够的缓存空间(即-m)。对于一些困难的情况(比如-c很大),会出现收敛很慢的情况.
你可以常识用一个较大点的终止可容忍偏差. 如果这样仍然不行,你可以和我们联系。我们会告诉你一些关于改善训练时间短小技巧。 </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A
name=f415><STRONG>问:我如何才能得到判决值?</STRONG></A> <BR></P>
<P>对于回归,程序可以打印出判决值。对于分类,可以通过解几个二进制SVMs来实现多分类,因此你可以通过调用子程序svm_predict_values来实现输出判决值。然后可以通过子程序svm_get_labels得到相应的标签值。详见软件包中的README文件。
</P>
<P>我们并不推荐以下操作,但是如果你要得到二分类的标签值+1和-1(注:这里的+1、-1和5、10的含义是不一样的),你只要在svm.cpp文件中的
svm_predict_values(model, x, dec_values)
后面添加:printf("%f\n",dec_values[0]*model->label[0])就可以了。 </P>
<P>正(负)判决值对应的值为+1(-1) </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A
name=f4151><STRONG>问:怎样得到一个点到超平面的距离?</STRONG></A><BR></P>
<P>距离的表达式为: |decision_value| / |w|.我们有: |w|^2 = w^Tw = alpha^T Q alpha =
2*(dual_obj + sum alpha_i). 因此在svm.pp文件中,知道输出对偶目标值的语句,在后面加上打印输出
w^Tw的语句就可以了. </P>
<P align=right><A
href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#_TOP">[Go Top]</A>
</P>
<HR>
<P><A name=/Q4:_Training_and_prediction></A><A
name=f416><STRONG>问:在linux操作系统上,对于一些问题,如果用很大的缓存(即很大的-m),有时候会出现“段错误”("segmentation
fault“),为什么?</STRONG></A> <BR></P>
<P>在32位机器上,最大可设地址空间为4GB。Linux核将其分成3:1,即:用户的空间为3GB,核空间为1G。尽管用户有3GB的存储空间,但是最大动态分配内存只有2GB。因此如果你将-m设为2G,内存将被耗尽。因此svm-train运行时候如果需要更多内存,程序就无法运行。详见<A
href="http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3BA164F6.BAFA4FB%40daimi.au.dk">此文</A>.
</P>
<P>有两中方法可以解决这个问题。如果你的机器支持Intel的物理地址扩展,你可以在Linux核中起用HIGHMEM64G选项,这样用户和核都将分配到4G的空间.
此外, 你还可以使用`tub'软件,它将为动态分配内存 elimate the 2G boundary . `tub' 可以到<A
href="http://www.bitwagon.com/tub.html">http://www.bitwagon.com/tub.html</A>下载.
<!--
This may happen only when the cache is large, but each cached row is
not large enough. <b>Note:</b> This problem is specific to
gnu C library which is used in linux.
The solution is as follows:
<p>
In our program we have malloc() which uses two methods
to allocate memory from kernel. One is
sbrk() and another is mmap(). sbrk is faster, but mmap
has a larger address
space. So malloc uses mmap only if the wanted memory size is larger
than some threshold (default 128k).
In the case where each row is not large enough (#elements < 128k/sizeof(float)) but we need a large cache ,
the address space for sbrk can be exhausted. The solution is to
lower the threshold to force malloc to use mmap
and increase the maximum number of chunks to allocate
with mmap.
<p>
Therefore, in the main program (i.e. svm-train.c) you want
to have
<pre>
#include <malloc.h>
</pre>
and then in main():
<pre>
mallopt(M_MMAP_THRESHOLD, 32768);
mallopt(M_MMAP_MAX,1000000);
</pre>
You can also set the environment variables instead
of writing them in the program:
<pre>
$ M_MMAP_MAX=1000000 M_MMAP_THRESHOLD=32768 ./svm-train .....
</pre>
More information can be found by
<pre>
$ info libc "Malloc Tunable Parameters"
</pre>
--></P>
<P align=right><A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -