📄 faq.html
字号:
<p>
"1-against-the rest" is a good method whose performance
is comparable to "1-against-1." We do the latter
simply because its training time is shorter.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q4:_Training_and_prediction"></a>
<a name="f420"><b>Q: After doing cross validation, why there is no model file outputted ?</b></a>
<br/>
<p>
Cross validation is used for selecting good parameters.
After finding them, you want to re-train the whole
data without the -v option.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q4:_Training_and_prediction"></a>
<a name="f421"><b>Q: I would like to try different random partition for cross validation, how could I do it ?</b></a>
<br/>
<p>
Right now we use the default seed so each time when you
run svm-train -v, folds of validation data are the same.
To have different seeds, you can add the following code
in svm-train.c:
<pre>
#include <time.h>
</pre>
and in the beginning of the subroutine do_cross_validation(),
<pre>
srand(time(0));
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q4:_Training_and_prediction"></a>
<a name="f422"><b>Q: I would like to solve L2-SVM (i.e., error term is quadratic). How should I modify the code ?</b></a>
<br/>
<p>
It is extremely easy. Taking c-svc for example, only two
places of svm.cpp have to be changed.
First, modify the following line of
solve_c_svc from
<pre>
s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
alpha, Cp, Cn, param->eps, si, param->shrinking, param->cal_partial, param->gamma);
</pre>
to
<pre>
s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
alpha, INF, INF, param->eps, si, param->shrinking, param->cal_partial, param->gamma);
</pre>
Second, in the class of SVC_Q, declare C as
a private variable:
<pre>
double C;
</pre>
In the constructor we assign it to param.C:
<pre>
this->C = param.C;
</pre>
Than in the the subroutine get_Q, after the for loop, add
<pre>
if(i >= start && i < len)
data[i] += 1/C;
</pre>
For one-class svm, the modification is exactly the same. For SVR, you don't need an if statement like the above. Instead, you only need a simple assignment:
<pre>
data[real_i] += 1/C;
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q4:_Training_and_prediction"></a>
<a name="f423"><b>Q: There seems to be a zero division ?</b></a>
<br/>
<p>
We intend
to have this zero division.
Under the IEEE floating point standard, zero
division will returns infinity. Then with the
operations later to bound it, things go back to normal numbers without any problem.
In general no warning messages happen. On some computers, you may
need to add an option (e.g. -mieee on alpha).
Reasons of doing so are described in libsvm document.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q4:_Training_and_prediction"></a>
<a name="f424"><b>Q: How do I choose parameters for one-class svm as training data are in only one class ?</b></a>
<br/>
<p>
You have pre-specified true positive rate in mind and then search for
parameters which achieve similar cross-validation accuracy.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q4:_Training_and_prediction"></a>
<a name="f425"><b>Q: Why training a probability model (i.e., -b 1) takes longer time ?</b></a>
<br/>
<p>
To construct this probability model, we internaly conduct a
cross validation, which is more time consuming than
a regular training.
Hence, in general you do parameter selection first without
-b 1. You only use -b 1 when good parameters have been
selected. In other words, you avoid using -b 1 and -v
together.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q5:_Graphic_Interface"></a>
<a name="f501"><b>Q: How can I save images drawn by svm-toy?</b></a>
<br/>
<p>
For Microsoft windows, first press the "print screen" key on the keyboard.
Open "Microsoft Paint"
(included in Windows)
and press "ctrl-v." Then you can clip
the part of picture which you want.
For X windows, you can
use the program "xv" to grab the picture of the svm-toy window.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q5:_Graphic_Interface"></a>
<a name="f502"><b>Q: I press the "load" button to load data points but why svm-toy does not draw them ?</b></a>
<br/>
<p>
The program svm-toy assumes both attributes (i.e. x-axis and y-axis
values) are in (0,1). Hence you want to scale your
data to between a small positive number and
a number less than but very close to 1.
Moreover, class labels must be 1, 2, or 3
(not 1.0, 2.0 or anything else).
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q5:_Graphic_Interface"></a>
<a name="f503"><b>Q: I would like svm-toy to handle more than three classes of data, what should I do ?</b></a>
<br/>
<p>
Taking windows/svm-toy.cpp as an example, you need to
modify it and the difference
from the original file is as the following: (for five classes of
data)
<pre>
30,32c30
< RGB(200,0,200),
< RGB(0,160,0),
< RGB(160,0,0)
---
> RGB(200,0,200)
39c37
< HBRUSH brush1, brush2, brush3, brush4, brush5;
---
> HBRUSH brush1, brush2, brush3;
113,114d110
< brush4 = CreateSolidBrush(colors[7]);
< brush5 = CreateSolidBrush(colors[8]);
155,157c151
< else if(v==3) return brush3;
< else if(v==4) return brush4;
< else return brush5;
---
> else return brush3;
325d318
< int colornum = 5;
327c320
< svm_node *x_space = new svm_node[colornum * prob.l];
---
> svm_node *x_space = new svm_node[3 * prob.l];
333,338c326,331
< x_space[colornum * i].index = 1;
< x_space[colornum * i].value = q->x;
< x_space[colornum * i + 1].index = 2;
< x_space[colornum * i + 1].value = q->y;
< x_space[colornum * i + 2].index = -1;
< prob.x[i] = &x_space[colornum * i];
---
> x_space[3 * i].index = 1;
> x_space[3 * i].value = q->x;
> x_space[3 * i + 1].index = 2;
> x_space[3 * i + 1].value = q->y;
> x_space[3 * i + 2].index = -1;
> prob.x[i] = &x_space[3 * i];
397c390
< if(current_value > 5) current_value = 1;
---
> if(current_value > 3) current_value = 1;
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q6:_Java_version_of_libsvm"></a>
<a name="f601"><b>Q: What is the difference between Java version and C++ version of libsvm?</b></a>
<br/>
<p>
They are the same thing. We just rewrote the C++ code
in Java.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q6:_Java_version_of_libsvm"></a>
<a name="f602"><b>Q: Is the Java version significantly slower than the C++ version?</b></a>
<br/>
<p>
This depends on the VM you used. We have seen good
VM which leads the Java version to be quite competitive with
the C++ code. (though still slower)
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q6:_Java_version_of_libsvm"></a>
<a name="f603"><b>Q: While training I get the following error message: java.lang.OutOfMemoryError. What is wrong?</b></a>
<br/>
<p>
You should try to increase the maximum Java heap size.
For example,
<pre>
java -Xmx256m svm_train.java ...
</pre>
sets the maximum heap size to 256M.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q6:_Java_version_of_libsvm"></a>
<a name="f604"><b>Q: Why you have the main source file svm.m4 and then transform it to svm.java?</b></a>
<br/>
<p>
Unlike C, Java does not have a preprocessor built-in.
However, we need some macros (see first 3 lines of svm.m4).
</ul>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q7:_Python_Interface"></a>
<a name="f702"><b>Q: Using python on MS windows, it fails to load the dll file.</b></a>
<br/>
<p>
It seems the dll file is version dependent. So far we haven't
found out a good solution. Please email us if you have any
good suggestions.
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q7:_Python_Interface"></a>
<a name="f703"><b>Q: How to modify the python interface on MS windows and rebuild the dll file ?</b></a>
<br/>
<p>
To modify the interface, follow the instructions given in
<a href=http://www.swig.org/Doc1.1/HTML/Python.html#n2>
http://www.swig.org/Doc1.1/HTML/Python.html#n2</a>
<p>
If you just want to build DLL for a different python version,
after libsvm 2.5, you can easily use the file Makefile.win.
See details in README.
Alternatively, you can use Visual C++:
<ol>
<li> Create a Win32 DLL project and set (Build->Active Configuration) to "Release."
<li> Add svm.cpp, svmc_wrap.c, python2x.lib to your project.
<li> Add the directories containing Python.h and svm.h to
the Additional include directories. (in Project
Settings->C/C++->Preprocessor)
<li> add __WIN32__ to Preprocessor definitions
<li> Make sure that in the "General" category of
Project->Settings->Settings For "Win32 Release", Output
directories should be "Release"
<li> Build the DLL.
</ol>
<!--
There do exist work arounds, however. In
http://aspn.activestate.com/ASPN/Mail/Message/python-list/983252
they presented a solution: 1) find the version of python in the
registry 2) perform LoadLibrary("pythonxx.dll") and 3) resolve the
reference to functions through GetProcAddress. It is said that SWIG
may help on this.
http://mailman.cs.uchicago.edu/pipermail/swig/2001-July/002744.html
presented a similar example.
-->
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q7:_Python_Interface"></a>
<a name="f704"><b>Q: Except the python-C++ interface provided, could I use Jython to call libsvm ?</b></a>
<br/>
<p> Yes, here are some examples:
<pre>
$ export CLASSPATH=$CLASSPATH:~/libsvm-2.4/java/libsvm.jar
$ ./jython
Jython 2.1a3 on java1.3.0 (JIT: jitc)
Type "copyright", "credits" or "license" for more information.
>>> from libsvm import *
>>> dir()
['__doc__', '__name__', 'svm', 'svm_model', 'svm_node', 'svm_parameter',
'svm_problem']
>>> x1 = [svm_node(index=1,value=1)]
>>> x2 = [svm_node(index=1,value=-1)]
>>> param = svm_parameter(svm_type=0,kernel_type=2,gamma=1,cache_size=40,eps=0.001,C=1,nr_weight=0,shrinking=1)
>>> prob = svm_problem(l=2,y=[1,-1],x=[x1,x2])
>>> model = svm.svm_train(prob,param)
*
optimization finished, #iter = 1
nu = 1.0
obj = -1.018315639346838, rho = 0.0
nSV = 2, nBSV = 2
Total nSV = 2
>>> svm.svm_predict(model,x1)
1.0
>>> svm.svm_predict(model,x2)
-1.0
>>> svm.svm_save_model("test.model",model)
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<a name="/Q7:_Python_Interface"></a>
<a name="f705"><b>Q: How could I install the python interface on Mac OS? </b></a>
<br/>
<p> According to S V N Vishwanathan in Australian National University, instead of
LDFLAGS = -shared
in the Makefile, you need
<pre>
LDFLAGS = -bundle -flat_namespace -undefined suppress
</pre>
<p align="right">
<a href="#_TOP">[Go Top]</a>
<hr/>
<p align="middle">
<a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm">LIBSVM home page</a>
</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -