📄 faq.html
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><html> <head> <title>libsvm faq</title> </head><body text="#000000" bgcolor="#FFEFD5" link="#FF0000" vlink="#0000FF"> <body> <h1><a href=http://www.csie.ntu.edu.tw/~cjlin/libsvm>LIBSVM</a> FAQ</h1><!-- Created: Wed Apr 18 19:26:54 CST 2001 --><!-- hhmts start -->Last modified: Wed Mar 31 10:49:17 CST 2004<!-- hhmts end --><hr><h3>Some courses which have used libsvm as a tool</h3><ul><li><a href=http://lmb.informatik.uni-freiburg.de/lectures/svm_seminar/>Institute for Computer Science, Faculty of Applied Science, University of Freiburg, Germany </a><li> <a href=http://www.cs.vu.nl/~elena/ml.html>Division of Mathematics and Computer Science. Faculteit der Exacte Wetenschappen Vrije Universiteit, The Netherlands. </a><li><a href=http://www.cae.wisc.edu/~ece539/matlab/>Electrical and Computer Engineering Department, University of Wisconsin-Madison </a><li><a href=http://www.hpl.hp.com/personal/Carl_Staelin/cs236601/project.html>Technion (Israel Institute of Technology), Israel.<li><a href=http://www.cise.ufl.edu/~fu/learn.html>Computer and Information Sciences Dept., University of Florida</a><li><a href=http://www.uonbi.ac.ke/acad_depts/ics/course_material/machine_learning/ML_and_DM_Resources.html>The Institute of Computer Science,University of Nairobi, Kenya.</a><li><a href=http://cerium.raunvis.hi.is/~tpr/courseware/svm/hugbunadur.html>Applied Mathematics and Computer Science, University of Iceland.</a></ul><hr><h3>Installation and and running the program</h3><ul><p><li> Where can I find documents of libsvm ? <p>In the package there is a README file which details all options, data format, and library calls.The model selection tool and the python interfacehave a separate README under the directory python.The guide<A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf">A practical guide to support vector classification</A> shows beginners how to train/test their data.The paper <a href="http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf">LIBSVM: a library for support vector machines</a> discusses the implementation oflibsvm in detail.<p><li> What are changes in previous versions? <p>See <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/log">the change log</a>.<p><li> I would like to cite libsvm. Which paper shouldI cite ?<p>Please cite the following document:<p>Chih-Chung Chang and Chih-Jen Lin, LIBSVM: a library for support vector machines, 2001.Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm<p>The bibtex format is as follows<pre>@Manual{CC01a, author = {Chih-Chung Chang and Chih-Jen Lin}, title = {{LIBSVM}: a library for support vector machines}, year = {2001}, note = {Software available at {\tt http://www.csie.ntu.edu.tw/\verb"~"cjlin/libsvm}},}</pre><p><li> I would like to use libsvm in my software. Is there any license problem ?<p>The libsvm license ("the modified BSD license")is compatible with manyfree software licenses such as GPL. Hence, it is very easy touse libsvm in your software.It can also be used in commercial products.<p><li> Is there a repository of additional toolsbased on libsvm ?<p>Yes, see <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvmtools">libsvm tools</a><p><li> On unix machines, I got "error in loading shared libraries"or "cannot open shared object file." What happened ?<p>This usually happens if you compile the codeon one machine and run it on another which has incompatiblelibraries.Try to recompile the program on that machine or use static linking.<p><li> I have modified the source and would like to build the graphic interface "svm-toy"on MS windows. How should I do it ?<p>Build it as a project by choosing "Win32 Application."On the other hand, for "svm-train" and "svm-predict"you want to choose "Win32 Console Application."After libsvm 2.5, you can also use the file Makefile.win.See details in README.<p><li>I am an MS windows user but whyonly one (SVM_toy) of those precompiled .exe actually runs ? <p>You need to open a command window and type svmtrain.exe to see all options.Some examples are in README file.</ul><hr><h3>Data preparation</h3><ul><p><li>Why sometimes not all attributes of a data appear in the training/model files ?<p>libsvm uses the so called "sparse" format where zerovalues do not need to be stored. Hence a data with attributes<pre>1 0 2 0</pre>is represented as<pre>1:1 3:2</pre><p><li>What if my data are non-numerical ?<p>Currently libsvm supports only numerical data.You may have to change non-numerical data to numerical. For example, you can use severalbinary attributes to represent a categoricalattribute.<p><li>Why do you consider sparse format ? Will the training of dense data be much slower ?<p>This is a controversial issue. The kernelevaluation (i.e. inner product) of sparse vectors is slower so the total training time can be at least twice or three timesof that using the dense format.However, we cannot support only dense format as then we CANNOThandle extremely sparse cases. Simplicity of the code is anotherconcern. Right now we decide to supportthe sparse format only.</ul><hr><h3>Training and prediction</h3><ul><p><li> The output of training C-SVM is like the following. What do they mean ?<br>optimization finished, #iter = 219<br>nu = 0.431030<br>obj = -100.877286, rho = 0.424632<br>nSV = 132, nBSV = 107<br>Total nSV = 132<p>obj is the optimal objective value of the dual SVM problem.rho is the bias term in the decision functionsgn(w^Tx - rho).nSV and nBSV are number of support vectors and bounded supportvectors (i.e., alpha_i = C). nu-svm is a somewhat equivalentform of C-SVM where C is replaced by nu. nu simply shows thecorresponding parameter. More details are in<a href="http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf">libsvm document</a>.<p><li> Can you explain more about the model file ?<p>After the parameters, each line represents a support vector.Support vectors are listed in the order of "labels" listed earlier.(i.e., those from the first class in the "labels" list aregrouped first, and so on.) If k is the total number of classes,in front of each support vector, there arek-1 coefficients y*alpha where alpha are dual solution of thefollowing two class problems:<br>1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k<br>and y=1 in first j-1 coefficients, y=-1 in the remainingk-j coefficients.For example, if there are 4 classes, the file looks like:<pre>+-+-+-+--------------------+|1|1|1| ||v|v|v| SVs from class 1 ||2|3|4| |+-+-+-+--------------------+|1|2|2| ||v|v|v| SVs from class 2 ||2|3|4| |+-+-+-+--------------------+|1|2|3| ||v|v|v| SVs from class 3 ||3|3|4| |+-+-+-+--------------------+|1|2|3| ||v|v|v| SVs from class 4 ||4|4|4| |+-+-+-+--------------------+</pre><p><li> Should I use float or double to store numbers in the cache ?<p>We have float as the default as you can store more numbersin the cache. In general this is good enough but for few difficultcases (e.g. C very very large) where solutions are hugenumbers, it might be possible that the numerical precision is notenough using only float.<p><li>How do I choose the kernel ?<p>In general we suggest you to try the RBF kernel first.A recent result by Keerthi and Lin(<a href=http://www.csie.ntu.edu.tw/~cjlin/papers/limit.ps.gz>download paper here</a>)shows that if RBF is used with model selection,then there is no need to consider the linear kernel.The kernel matrix using sigmoid may not be positive definiteand in general it's accuracy is not better than RBF.(see the paper by Lin and Lin(<a href=http://www.csie.ntu.edu.tw/~cjlin/papers/tanh.pdf>download paper here</a>).Polynomial kernels are ok but if a high degree is used,numerical difficulties tend to happen(thinking about dth power of (<1) goes to 0and (>1) goes to infinity). <p><li> Does libsvm have special treatmentsfor linear SVM ?<p>No, at this point libsvm solves linear/nonlinear SVMs by thesame way.Note that there are some possibletricks to save training/testing time if thelinear kernel is used.Hence libsvm is <b>NOT</b> particularly efficient for linear SVM,especially for problems whose number of data is much largerthan number of attributes.If you plan to solve this type of problems, you may want to check <a href=http://www.csie.ntu.edu.tw/~cjlin/bsvm>bsvm</a>,which includes an efficient implementation forlinear SVMs.More details can be found in the following study:K.-M. Chung, W.-C. Kao, T. Sun, andC.-J. Lin.<A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/linear.pdf">Decomposition Methods for Linear Support Vector Machines</a><p> On the other hand, you do not really need to solvelinear SVMs. See the previous question about choosingkernels for details.<p><li>The number of free support vectors is large. What should I do ? <p>This usually happens when the data are overfitted.If attributes of your data are in large ranges,try to scale them. Then the regionof appropriate parameters may be larger.Note that there is a scale programin libsvm. <p><li>Should I scale training and testing data in a similar way ?<p>Yes, you can do the following:<br> svm-scale -s scaling_parameters train_data > scaled_train_data<br> svm-scale -r scaling_parameters test_data > scaled_test_data<p><li>Does it make a big difference if I scale each attributeto [0,1] instead of [-1,1] ?<p>For the linear scaling method, if the RBF kernel isused and parameter selection is conducted, thereis no difference. Assume Mi and mi are respectively the maximal and minimal values of theith attribute. Scaling to [0,1] means<pre> x'=(x-mi)/(Mi-mi)</pre>For [-1,1],<pre> x''=2(x-mi)/(Mi-mi)-1.</pre>In the RBF kernel,<pre> x'-y'=(x-y)/(Mi-mi), x''-y''=2(x-y)/(Mi-mi).</pre>Hence, using (C,g) on the [0,1]-scaled data is thesame as (C,g/2) on the [-1,1]-scaled data.<p> Though the performance is the same, the computationaltime may be different. For data with many zero entries,[0,1]-scaling keeps the sparsity of input data and hencemay save the time.<p><li>The prediction rate is low. How could I improve it ?<p>Try to use the model selection tool grid.py in the pythondirectory findout good parameters. To see the importance of model selection,please see my talk:<A HREF="http://www.csie.ntu.edu.tw/~cjlin/talks/tuebingen.ps.gz">Can support vector machines become a major classification method ? </A><p><li>My data are unbalanced. Could libsvm handle such problems ?<p>Yes, there is a -wi options. For example, if you use<p> svm-train -s 0 -c 10 -w1 1 -w-1 5 data_file<p>the penalty for class "-1" is larger.Note that this -w option is for C-SVC only.<p><li>What is the difference between nu-SVC and C-SVC ?<p>Basically they are the same thing but with differentparameters. The range of C is from zero to infinitybut nu is always between [0,1]. A nice propertyof nu is that it is related to the ratio of support vectors and the ratio of the trainingerror.<p><li>The program keeps running without showingany output. What should I do ?<p>You may want to check your data. Each training/testingdata must be in one line. It cannot be separated.In addition, you have to remove empty lines.<p><li>The program keeps running (with output, i.e. many dots).What should I do ?<p>In theory libsvm guarantees to converge if the kernelmatrix is positive semidefinite. After version 2.4 it can also handle non-PSDkernels such as the sigmoid (tanh).Therefore, this means you arehandling ill-conditioned situations(e.g. too large/small parameters) so numericaldifficulties occur.<p><li>The training time is too long. What should I do ?<p>This may happen for some difficult cases (e.g. -c is large).You can try to use a looser stopping tolerance with -e.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -