📄 faq.html
字号:
If that still doesn't work, you may want to contact us. We can show you sometricks on improving the training time.<p><li> How do I get the decision value(s) ?<p>We print out decision values for regression. For classification,we solve several binary SVMs for multi-class cases, so you obtain values by easily calling the subroutinesvm_predict_values. Their corresponding labelscan be obtained from svm_get_labels. Details are in README of libsvm package. <p>We do not recommend the following. But if you wouldlike to get values for TWO-class classification with labels +1 and -1(note: +1 and -1 but not things like 5 and 10)in the easiest way, simply add <pre> printf("%f\n", dec_values[0]*model->label[0]);</pre>after the line<pre> svm_predict_values(model, x, dec_values);</pre>of the file svm.cpp.Positive (negative)decision values correspond to data predicted as +1 (-1).<!--<p><li>For some problem sets if I use a large cache (i.e. large -m) on a linux machine, why sometimesI get "segmentation fault ?"<p>This may happen only when the cache is large, but each cached row isnot 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 issbrk() and another is mmap(). sbrk is faster, but mmap has a larger addressspace. So malloc uses mmap only if the wanted memory size is largerthan 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 tolower the threshold to force malloc to use mmapand increase the maximum number of chunks to allocatewith mmap.<p>Therefore, in the main program (i.e. svm-train.c) you wantto 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 insteadof 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><li>How do I disable screen output of svm-train and svm-predict ?<p>Simply update svm.cpp:<pre>#if 1void info(char *fmt,...)</pre>to<pre>#if 0void info(char *fmt,...)</pre><p><li>I would like to use my own kernel but find out thatthere are two subroutines for kernel evaluations: k_function() and kernel_function(). Which oneshould I modify ?<p>The reason why we have two functions is as follows:For the RBF kernel exp(-g |xi - xj|^2), if we calculatexi - xj first and then the norm square, there are 3n operations.Thus we consider exp(-g (|xi|^2 - 2dot(xi,xj) +|xj|^2))and by calculating all |xi|^2 in the beginning, the number of operations is reduced to 2n.This is for the training. For prediction we cannotdo this so a regular subroutine using that 3n operations isneeded.The easiest way to have your own kernel isto put the same code in these twosubroutines by replacing any kernel.<p><li>What method does libsvm use for multi-class SVM ?<p>It is one-against-one. We chose it after doing the followingcomparison:C.-W. Hsu and C.-J. Lin.<A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/multisvm.ps.gz">A comparison of methods for multi-class support vector machines</A>, <I>IEEE Transactions on Neural Networks</A></I>, 13(2002), 415-425.<p><li> After doing cross validation, why there is nomodel file outputted ?<p>Cross validation is used for selecting good parameters.After finding them, you want to re-train the wholedata without the -v option.<p><li> I would like to try different random partitionfor cross validation, how could I do it ?<p>Right now we use the default seed so each time when yourun svm-train -v, folds of validation data are the same.To have different seeds, you can add the following codein svm-train.c:<pre>#include <time.h></pre>and in the beginning of the subroutine do_cross_validation(),<pre>srand(time(0));</pre><p><li> I would like to solve L2-SVM (i.e., error term is quadratic). How should I modify the code ?<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><p><li> There seems to be a zero division ?<p>We intendto have this zero division. Under the IEEE floating point standard, zerodivision 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 mayneed to add an option (e.g. -mieee on alpha).Reasons of doing so are described in libsvm document.<p><li> How do I choose parameters for one-class svm as training data are in only one class ?<p>You have pre-specified true positive rate in mind and then search forparameters which achieve similar cross-validation accuracy.</ul><hr><h3>Graphic Interface</h3><ul><p><li>How can I save images drawn by svm-toy? <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 clipthe 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><li>I press the "load" button to load data points but whysvm-toy does not draw them ?<p>The program svm-toy assumes both attributes (i.e. x-axis and y-axisvalues) 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.<p><li>I would like svm-toy to handle more than three classes ofdata, what should I do ?<p>Taking windows/svm-toy.cpp as an example, you need tomodify it and the differencefrom the original file is as the following: (for five classes ofdata)<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></ul><hr><h3>Java version of libsvm</h3><ul><p><li>What is the difference between Java version and C++version of libsvm?<p>They are the same thing. We just rewrote the C++ codein Java.<p><li>Is the Java version significantly slower than theC++ version?<p>This depends on the VM you used. We have seen goodVM which leads the Java version to be quite competitive withthe C++ code. (though still slower)<p><li> While training I get the following error message: java.lang.OutOfMemoryError. What is wrong?<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><li> Why you have the main source file svm.m4 and then transform it to svm.java?<p>Unlike C, Java does not have a preprocessor built-in.However, we need some macros (see first 3 lines of svm.m4).</ul><hr><h3>Python Interface</h3><ul><!--<p><li> I include libsvm-python interface in my scripts butget "segmentation fault" ?<p>There are two bugs in svm.py (version 2.35). Please manually correct them before we release the new version.First, please add <pre> self.prob = prob</pre>after the line<pre> prob,param = arg1,arg2</pre>in svm.py<p>Second, please move the first line of svm_parameter.__del__ to the last, sothe function becomes:<pre> def __del__(self): _free_int_array(self.weight_label) _free_double_array(self.weight) svmc.delete_svm_parameter(self.param)</pre>--><p><li>Using python on MS windows, it fails to load the dll file.<p>It seems the dll file is version dependent. So far we haven'tfound out a good solution. Please email us if you have anygood suggestions.<p><li> How to modify the python interface on MS windowsand rebuild the dll file ?<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 tothe Additional include directories. (in ProjectSettings->C/C++->Preprocessor)<li> add __WIN32__ to Preprocessor definitions<li> Make sure that in the "General" category ofProject->Settings->Settings For "Win32 Release", Outputdirectories should be "Release"<li> Build the DLL.</ol><!--There do exist work arounds, however. Inhttp://aspn.activestate.com/ASPN/Mail/Message/python-list/983252they presented a solution: 1) find the version of python in theregistry 2) perform LoadLibrary("pythonxx.dll") and 3) resolve thereference to functions through GetProcAddress. It is said that SWIGmay help on this.http://mailman.cs.uchicago.edu/pipermail/swig/2001-July/002744.htmlpresented a similar example.--><p><li>Except the python-C++ interface provided, could I use Jython to call libsvm ?<p> Yes, an example is <a href=http://www.csie.ntu.edu.tw/~cjlin/libsvm/jython>here</a></ul> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -