FAQ.html 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  1. <html>
  2. <head>
  3. <title>LIBSVM FAQ</title>
  4. </head>
  5. <body bgcolor="#ffffcc">
  6. <a name="_TOP"><b><h1><a
  7. href=http://www.csie.ntu.edu.tw/~cjlin/libsvm>LIBSVM</a> FAQ </h1></b></a>
  8. <b>last modified : </b>
  9. Fri, 14 Mar 2008 23:36:32 GMT
  10. <class="categories">
  11. <li><a
  12. href="#_TOP">All Questions</a>(66)</li>
  13. <ul><b>
  14. <li><a
  15. href="#/Q1:_Some_sample_uses_of_libsvm">Q1:_Some_sample_uses_of_libsvm</a>(2)</li>
  16. <li><a
  17. href="#/Q2:_Installation_and_running_the_program">Q2:_Installation_and_running_the_program</a>(8)</li>
  18. <li><a
  19. href="#/Q3:_Data_preparation">Q3:_Data_preparation</a>(6)</li>
  20. <li><a
  21. href="#/Q4:_Training_and_prediction">Q4:_Training_and_prediction</a>(30)</li>
  22. <li><a
  23. href="#/Q5:_Probability_outputs">Q5:_Probability_outputs</a>(3)</li>
  24. <li><a
  25. href="#/Q6:_Graphic_interface">Q6:_Graphic_interface</a>(3)</li>
  26. <li><a
  27. href="#/Q7:_Java_version_of_libsvm">Q7:_Java_version_of_libsvm</a>(4)</li>
  28. <li><a
  29. href="#/Q8:_Python_interface">Q8:_Python_interface</a>(5)</li>
  30. <li><a
  31. href="#/Q9:_MATLAB_interface">Q9:_MATLAB_interface</a>(5)</li>
  32. </b></ul>
  33. </li>
  34. <ul><ul class="headlines">
  35. <li class="headlines_item"><a href="#faq101">Some courses which have used libsvm as a tool</a></li>
  36. <li class="headlines_item"><a href="#faq102">Some applications which have used libsvm </a></li>
  37. <li class="headlines_item"><a href="#f201">Where can I find documents of libsvm ?</a></li>
  38. <li class="headlines_item"><a href="#f202">What are changes in previous versions?</a></li>
  39. <li class="headlines_item"><a href="#f203">I would like to cite libsvm. Which paper should I cite ? </a></li>
  40. <li class="headlines_item"><a href="#f204">I would like to use libsvm in my software. Is there any license problem?</a></li>
  41. <li class="headlines_item"><a href="#f205">Is there a repository of additional tools based on libsvm?</a></li>
  42. <li class="headlines_item"><a href="#f206">On unix machines, I got "error in loading shared libraries" or "cannot open shared object file." What happened ? </a></li>
  43. <li class="headlines_item"><a href="#f207">I have modified the source and would like to build the graphic interface "svm-toy" on MS windows. How should I do it ?</a></li>
  44. <li class="headlines_item"><a href="#f208">I am an MS windows user but why only one (svm-toy) of those precompiled .exe actually runs ? </a></li>
  45. <li class="headlines_item"><a href="#f301">Why sometimes not all attributes of a data appear in the training/model files ?</a></li>
  46. <li class="headlines_item"><a href="#f302">What if my data are non-numerical ?</a></li>
  47. <li class="headlines_item"><a href="#f303">Why do you consider sparse format ? Will the training of dense data be much slower ?</a></li>
  48. <li class="headlines_item"><a href="#f304">Why sometimes the last line of my data is not read by svm-train?</a></li>
  49. <li class="headlines_item"><a href="#f305">Is there a program to check if my data are in the correct format?</a></li>
  50. <li class="headlines_item"><a href="#f306">May I put comments in data files?</a></li>
  51. <li class="headlines_item"><a href="#431">I don't know class labels of test data. What should I put in the first column of the test file?</a></li>
  52. <li class="headlines_item"><a href="#f401">The output of training C-SVM is like the following. What do they mean?</a></li>
  53. <li class="headlines_item"><a href="#f402">Can you explain more about the model file?</a></li>
  54. <li class="headlines_item"><a href="#f403">Should I use float or double to store numbers in the cache ?</a></li>
  55. <li class="headlines_item"><a href="#f404">How do I choose the kernel?</a></li>
  56. <li class="headlines_item"><a href="#f405">Does libsvm have special treatments for linear SVM?</a></li>
  57. <li class="headlines_item"><a href="#f406">The number of free support vectors is large. What should I do?</a></li>
  58. <li class="headlines_item"><a href="#f407">Should I scale training and testing data in a similar way?</a></li>
  59. <li class="headlines_item"><a href="#f408">Does it make a big difference if I scale each attribute to [0,1] instead of [-1,1]?</a></li>
  60. <li class="headlines_item"><a href="#f409">The prediction rate is low. How could I improve it?</a></li>
  61. <li class="headlines_item"><a href="#f410">My data are unbalanced. Could libsvm handle such problems?</a></li>
  62. <li class="headlines_item"><a href="#f411">What is the difference between nu-SVC and C-SVC?</a></li>
  63. <li class="headlines_item"><a href="#f412">The program keeps running (without showing any output). What should I do?</a></li>
  64. <li class="headlines_item"><a href="#f413">The program keeps running (with output, i.e. many dots). What should I do?</a></li>
  65. <li class="headlines_item"><a href="#f414">The training time is too long. What should I do?</a></li>
  66. <li class="headlines_item"><a href="#f415">How do I get the decision value(s)?</a></li>
  67. <li class="headlines_item"><a href="#f4151">How do I get the distance between a point and the hyperplane?</a></li>
  68. <li class="headlines_item"><a href="#f416">On 32-bit machines, if I use a large cache (i.e. large -m) on a linux machine, why sometimes I get "segmentation fault ?"</a></li>
  69. <li class="headlines_item"><a href="#f417">How do I disable screen output of svm-train and svm-predict ?</a></li>
  70. <li class="headlines_item"><a href="#f418">I would like to use my own kernel but find out that there are two subroutines for kernel evaluations: k_function() and kernel_function(). Which one should I modify ?</a></li>
  71. <li class="headlines_item"><a href="#f419">What method does libsvm use for multi-class SVM ? Why don't you use the "1-against-the rest" method ?</a></li>
  72. <li class="headlines_item"><a href="#f420">After doing cross validation, why there is no model file outputted ?</a></li>
  73. <li class="headlines_item"><a href="#f4201">Why my cross-validation results are different from those in the Practical Guide?</a></li>
  74. <li class="headlines_item"><a href="#f421">But on some systems CV accuracy is the same in several runs. How could I use different data partitions?</a></li>
  75. <li class="headlines_item"><a href="#f422">I would like to solve L2-loss SVM (i.e., error term is quadratic). How should I modify the code ?</a></li>
  76. <li class="headlines_item"><a href="#f424">How do I choose parameters for one-class svm as training data are in only one class?</a></li>
  77. <li class="headlines_item"><a href="#f427">Why the code gives NaN (not a number) results?</a></li>
  78. <li class="headlines_item"><a href="#f428">Why on windows sometimes grid.py fails?</a></li>
  79. <li class="headlines_item"><a href="#f429">Why grid.py/easy.py sometimes generates the following warning message?</a></li>
  80. <li class="headlines_item"><a href="#f430">Why the sign of predicted labels and decision values are sometimes reversed?</a></li>
  81. <li class="headlines_item"><a href="#f425">Why training a probability model (i.e., -b 1) takes longer time</a></li>
  82. <li class="headlines_item"><a href="#f426">Why using the -b option does not give me better accuracy?</a></li>
  83. <li class="headlines_item"><a href="#f427">Why using svm-predict -b 0 and -b 1 gives different accuracy values?</a></li>
  84. <li class="headlines_item"><a href="#f501">How can I save images drawn by svm-toy?</a></li>
  85. <li class="headlines_item"><a href="#f502">I press the "load" button to load data points but why svm-toy does not draw them ?</a></li>
  86. <li class="headlines_item"><a href="#f503">I would like svm-toy to handle more than three classes of data, what should I do ?</a></li>
  87. <li class="headlines_item"><a href="#f601">What is the difference between Java version and C++ version of libsvm?</a></li>
  88. <li class="headlines_item"><a href="#f602">Is the Java version significantly slower than the C++ version?</a></li>
  89. <li class="headlines_item"><a href="#f603">While training I get the following error message: java.lang.OutOfMemoryError. What is wrong?</a></li>
  90. <li class="headlines_item"><a href="#f604">Why you have the main source file svm.m4 and then transform it to svm.java?</a></li>
  91. <li class="headlines_item"><a href="#f702">On MS windows, why does python fail to load the pyd file?</a></li>
  92. <li class="headlines_item"><a href="#f703">How to modify the python interface on MS windows and rebuild the .pyd file ?</a></li>
  93. <li class="headlines_item"><a href="#f704">Except the python-C++ interface provided, could I use Jython to call libsvm ?</a></li>
  94. <li class="headlines_item"><a href="#f705">How could I install the python interface on Mac OS? </a></li>
  95. <li class="headlines_item"><a href="#f706">I typed "make" on a unix system, but it says "Python.h: No such file or directory?"</a></li>
  96. <li class="headlines_item"><a href="#f801">I compile the MATLAB interface without problem, but why errors occur while running it?</a></li>
  97. <li class="headlines_item"><a href="#f802">Does the MATLAB interface provide a function to do scaling?</a></li>
  98. <li class="headlines_item"><a href="#f803">How could I use MATLAB interface for parameter selection?</a></li>
  99. <li class="headlines_item"><a href="#f804">How could I generate the primal variable w of linear SVM?</a></li>
  100. <li class="headlines_item"><a href="#f805">Is there an OCTAVE interface for libsvm?</a></li>
  101. </ul></ul>
  102. <hr size="5" noshade />
  103. <p/>
  104. <a name="/Q1:_Some_sample_uses_of_libsvm"></a>
  105. <a name="faq101"><b>Q: Some courses which have used libsvm as a tool</b></a>
  106. <br/>
  107. <ul>
  108. <li><a href=http://lmb.informatik.uni-freiburg.de/lectures/svm_seminar/>Institute for Computer Science,
  109. Faculty of Applied Science, University of Freiburg, Germany
  110. </a>
  111. <li> <a href=http://www.cs.vu.nl/~elena/ml.html>
  112. Division of Mathematics and Computer Science.
  113. Faculteit der Exacte Wetenschappen
  114. Vrije Universiteit, The Netherlands. </a>
  115. <li>
  116. <a href=http://www.cae.wisc.edu/~ece539/matlab/>
  117. Electrical and Computer Engineering Department,
  118. University of Wisconsin-Madison
  119. </a>
  120. <li>
  121. <a href=http://www.hpl.hp.com/personal/Carl_Staelin/cs236601/project.html>
  122. Technion (Israel Institute of Technology), Israel.
  123. <li>
  124. <a href=http://www.cise.ufl.edu/~fu/learn.html>
  125. Computer and Information Sciences Dept., University of Florida</a>
  126. <li>
  127. <a href=http://www.uonbi.ac.ke/acad_depts/ics/course_material/machine_learning/ML_and_DM_Resources.html>
  128. The Institute of Computer Science,
  129. University of Nairobi, Kenya.</a>
  130. <li>
  131. <a href=http://cerium.raunvis.hi.is/~tpr/courseware/svm/hugbunadur.html>
  132. Applied Mathematics and Computer Science, University of Iceland.
  133. <li>
  134. <a href=http://chicago05.mlss.cc/tiki/tiki-read_article.php?articleId=2>
  135. SVM tutorial in machine learning
  136. summer school, University of Chicago, 2005.
  137. </a>
  138. </ul>
  139. <p align="right">
  140. <a href="#_TOP">[Go Top]</a>
  141. <hr/>
  142. <a name="/Q1:_Some_sample_uses_of_libsvm"></a>
  143. <a name="faq102"><b>Q: Some applications which have used libsvm </b></a>
  144. <br/>
  145. <ul>
  146. <li><a href=http://johel.m.free.fr/demo_045.htm>
  147. Realtime object recognition</a>
  148. </ul>
  149. <p align="right">
  150. <a href="#_TOP">[Go Top]</a>
  151. <hr/>
  152. <a name="/Q2:_Installation_and_running_the_program"></a>
  153. <a name="f201"><b>Q: Where can I find documents of libsvm ?</b></a>
  154. <br/>
  155. <p>
  156. In the package there is a README file which
  157. details all options, data format, and library calls.
  158. The model selection tool and the python interface
  159. have a separate README under the directory python.
  160. The guide
  161. <A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf">
  162. A practical guide to support vector classification
  163. </A> shows beginners how to train/test their data.
  164. The paper <a href="http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf">LIBSVM
  165. : a library for support vector machines</a> discusses the implementation of
  166. libsvm in detail.
  167. <p align="right">
  168. <a href="#_TOP">[Go Top]</a>
  169. <hr/>
  170. <a name="/Q2:_Installation_and_running_the_program"></a>
  171. <a name="f202"><b>Q: What are changes in previous versions?</b></a>
  172. <br/>
  173. <p>See <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/log">the change log</a>.
  174. <p> You can download earlier versions
  175. <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/oldfiles">here</a>.
  176. <p align="right">
  177. <a href="#_TOP">[Go Top]</a>
  178. <hr/>
  179. <a name="/Q2:_Installation_and_running_the_program"></a>
  180. <a name="f203"><b>Q: I would like to cite libsvm. Which paper should I cite ? </b></a>
  181. <br/>
  182. <p>
  183. Please cite the following document:
  184. <p>
  185. Chih-Chung Chang and Chih-Jen Lin, LIBSVM
  186. : a library for support vector machines, 2001.
  187. Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm
  188. <p>
  189. The bibtex format is as follows
  190. <pre>
  191. @Manual{CC01a,
  192. author = {Chih-Chung Chang and Chih-Jen Lin},
  193. title = {{LIBSVM}: a library for support vector machines},
  194. year = {2001},
  195. note = {Software available at \url{http://www.csie.ntu.edu.tw/~cjlin/libsvm}}
  196. }
  197. </pre>
  198. <p align="right">
  199. <a href="#_TOP">[Go Top]</a>
  200. <hr/>
  201. <a name="/Q2:_Installation_and_running_the_program"></a>
  202. <a name="f204"><b>Q: I would like to use libsvm in my software. Is there any license problem?</b></a>
  203. <br/>
  204. <p>
  205. The libsvm license ("the modified BSD license")
  206. is compatible with many
  207. free software licenses such as GPL. Hence, it is very easy to
  208. use libsvm in your software.
  209. It can also be used in commercial products.
  210. <p align="right">
  211. <a href="#_TOP">[Go Top]</a>
  212. <hr/>
  213. <a name="/Q2:_Installation_and_running_the_program"></a>
  214. <a name="f205"><b>Q: Is there a repository of additional tools based on libsvm?</b></a>
  215. <br/>
  216. <p>
  217. Yes, see <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvmtools">libsvm
  218. tools</a>
  219. <p align="right">
  220. <a href="#_TOP">[Go Top]</a>
  221. <hr/>
  222. <a name="/Q2:_Installation_and_running_the_program"></a>
  223. <a name="f206"><b>Q: On unix machines, I got "error in loading shared libraries" or "cannot open shared object file." What happened ? </b></a>
  224. <br/>
  225. <p>
  226. This usually happens if you compile the code
  227. on one machine and run it on another which has incompatible
  228. libraries.
  229. Try to recompile the program on that machine or use static linking.
  230. <p align="right">
  231. <a href="#_TOP">[Go Top]</a>
  232. <hr/>
  233. <a name="/Q2:_Installation_and_running_the_program"></a>
  234. <a name="f207"><b>Q: I have modified the source and would like to build the graphic interface "svm-toy" on MS windows. How should I do it ?</b></a>
  235. <br/>
  236. <p>
  237. Build it as a project by choosing "Win32 Project."
  238. On the other hand, for "svm-train" and "svm-predict"
  239. you want to choose "Win32 Console Project."
  240. After libsvm 2.5, you can also use the file Makefile.win.
  241. See details in README.
  242. <p>
  243. If you are not using Makefile.win and see the following
  244. link error
  245. <pre>
  246. LIBCMTD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol
  247. _wWinMain@16
  248. </pre>
  249. you may have selected a wrong project type.
  250. <p align="right">
  251. <a href="#_TOP">[Go Top]</a>
  252. <hr/>
  253. <a name="/Q2:_Installation_and_running_the_program"></a>
  254. <a name="f208"><b>Q: I am an MS windows user but why only one (svm-toy) of those precompiled .exe actually runs ? </b></a>
  255. <br/>
  256. <p>
  257. You need to open a command window
  258. and type svmtrain.exe to see all options.
  259. Some examples are in README file.
  260. <p align="right">
  261. <a href="#_TOP">[Go Top]</a>
  262. <hr/>
  263. <a name="/Q3:_Data_preparation"></a>
  264. <a name="f301"><b>Q: Why sometimes not all attributes of a data appear in the training/model files ?</b></a>
  265. <br/>
  266. <p>
  267. libsvm uses the so called "sparse" format where zero
  268. values do not need to be stored. Hence a data with attributes
  269. <pre>
  270. 1 0 2 0
  271. </pre>
  272. is represented as
  273. <pre>
  274. 1:1 3:2
  275. </pre>
  276. <p align="right">
  277. <a href="#_TOP">[Go Top]</a>
  278. <hr/>
  279. <a name="/Q3:_Data_preparation"></a>
  280. <a name="f302"><b>Q: What if my data are non-numerical ?</b></a>
  281. <br/>
  282. <p>
  283. Currently libsvm supports only numerical data.
  284. You may have to change non-numerical data to
  285. numerical. For example, you can use several
  286. binary attributes to represent a categorical
  287. attribute.
  288. <p align="right">
  289. <a href="#_TOP">[Go Top]</a>
  290. <hr/>
  291. <a name="/Q3:_Data_preparation"></a>
  292. <a name="f303"><b>Q: Why do you consider sparse format ? Will the training of dense data be much slower ?</b></a>
  293. <br/>
  294. <p>
  295. This is a controversial issue. The kernel
  296. evaluation (i.e. inner product) of sparse vectors is slower
  297. so the total training time can be at least twice or three times
  298. of that using the dense format.
  299. However, we cannot support only dense format as then we CANNOT
  300. handle extremely sparse cases. Simplicity of the code is another
  301. concern. Right now we decide to support
  302. the sparse format only.
  303. <p align="right">
  304. <a href="#_TOP">[Go Top]</a>
  305. <hr/>
  306. <a name="/Q3:_Data_preparation"></a>
  307. <a name="f304"><b>Q: Why sometimes the last line of my data is not read by svm-train?</b></a>
  308. <br/>
  309. <p>
  310. We assume that you have '\n' in the end of
  311. each line. So please press enter in the end
  312. of your last line.
  313. <p align="right">
  314. <a href="#_TOP">[Go Top]</a>
  315. <hr/>
  316. <a name="/Q3:_Data_preparation"></a>
  317. <a name="f305"><b>Q: Is there a program to check if my data are in the correct format?</b></a>
  318. <br/>
  319. <p>
  320. The svm-train program in libsvm conducts only a simple check of the input data. To do a
  321. detailed check, after libsvm 2.85, you can use the python script tools/checkdata.py. See tools/README for details.
  322. <p align="right">
  323. <a href="#_TOP">[Go Top]</a>
  324. <hr/>
  325. <a name="/Q3:_Data_preparation"></a>
  326. <a name="f306"><b>Q: May I put comments in data files?</b></a>
  327. <br/>
  328. <p>
  329. No, for simplicity we don't support that.
  330. However, you can easily preprocess your data before
  331. using libsvm. For example,
  332. if you have the following data
  333. <pre>
  334. test.txt
  335. 1 1:2 2:1 # proten A
  336. </pre>
  337. then on unix machines you can do
  338. <pre>
  339. cut -d '#' -f 1 < test.txt > test.features
  340. cut -d '#' -f 2 < test.txt > test.comments
  341. svm-predict test.feature train.model test.predicts
  342. paste -d '#' test.predicts test.comments | sed 's/#/ #/' > test.results
  343. </pre>
  344. <p align="right">
  345. <a href="#_TOP">[Go Top]</a>
  346. <hr/>
  347. <a name="/Q4:_Training_and_prediction"></a>
  348. <a name="431"><b>Q: I don't know class labels of test data. What should I put in the first column of the test file?</b></a>
  349. <br/>
  350. <p>Any value is ok. In this situation, what you will use is the output file of svm-predict, which gives predicted class labels.
  351. <p align="right">
  352. <a href="#_TOP">[Go Top]</a>
  353. <hr/>
  354. <a name="/Q4:_Training_and_prediction"></a>
  355. <a name="f401"><b>Q: The output of training C-SVM is like the following. What do they mean?</b></a>
  356. <br/>
  357. <br>optimization finished, #iter = 219
  358. <br>nu = 0.431030
  359. <br>obj = -100.877286, rho = 0.424632
  360. <br>nSV = 132, nBSV = 107
  361. <br>Total nSV = 132
  362. <p>
  363. obj is the optimal objective value of the dual SVM problem.
  364. rho is the bias term in the decision function
  365. sgn(w^Tx - rho).
  366. nSV and nBSV are number of support vectors and bounded support
  367. vectors (i.e., alpha_i = C). nu-svm is a somewhat equivalent
  368. form of C-SVM where C is replaced by nu. nu simply shows the
  369. corresponding parameter. More details are in
  370. <a href="http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf">
  371. libsvm document</a>.
  372. <p align="right">
  373. <a href="#_TOP">[Go Top]</a>
  374. <hr/>
  375. <a name="/Q4:_Training_and_prediction"></a>
  376. <a name="f402"><b>Q: Can you explain more about the model file?</b></a>
  377. <br/>
  378. <p>
  379. After the parameters, each line represents a support vector.
  380. Support vectors are listed in the order of "labels" listed earlier.
  381. (i.e., those from the first class in the "labels" list are
  382. grouped first, and so on.)
  383. If k is the total number of classes,
  384. in front of each support vector, there are
  385. k-1 coefficients
  386. y*alpha where alpha are dual solution of the
  387. following two class problems:
  388. <br>
  389. 1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k
  390. <br>
  391. and y=1 in first j-1 coefficients, y=-1 in the remaining
  392. k-j coefficients.
  393. For example, if there are 4 classes, the file looks like:
  394. <pre>
  395. +-+-+-+--------------------+
  396. |1|1|1| |
  397. |v|v|v| SVs from class 1 |
  398. |2|3|4| |
  399. +-+-+-+--------------------+
  400. |1|2|2| |
  401. |v|v|v| SVs from class 2 |
  402. |2|3|4| |
  403. +-+-+-+--------------------+
  404. |1|2|3| |
  405. |v|v|v| SVs from class 3 |
  406. |3|3|4| |
  407. +-+-+-+--------------------+
  408. |1|2|3| |
  409. |v|v|v| SVs from class 4 |
  410. |4|4|4| |
  411. +-+-+-+--------------------+
  412. </pre>
  413. <p align="right">
  414. <a href="#_TOP">[Go Top]</a>
  415. <hr/>
  416. <a name="/Q4:_Training_and_prediction"></a>
  417. <a name="f403"><b>Q: Should I use float or double to store numbers in the cache ?</b></a>
  418. <br/>
  419. <p>
  420. We have float as the default as you can store more numbers
  421. in the cache.
  422. In general this is good enough but for few difficult
  423. cases (e.g. C very very large) where solutions are huge
  424. numbers, it might be possible that the numerical precision is not
  425. enough using only float.
  426. <p align="right">
  427. <a href="#_TOP">[Go Top]</a>
  428. <hr/>
  429. <a name="/Q4:_Training_and_prediction"></a>
  430. <a name="f404"><b>Q: How do I choose the kernel?</b></a>
  431. <br/>
  432. <p>
  433. In general we suggest you to try the RBF kernel first.
  434. A recent result by Keerthi and Lin
  435. (<a href=http://www.csie.ntu.edu.tw/~cjlin/papers/limit.ps.gz>
  436. download paper here</a>)
  437. shows that if RBF is used with model selection,
  438. then there is no need to consider the linear kernel.
  439. The kernel matrix using sigmoid may not be positive definite
  440. and in general it's accuracy is not better than RBF.
  441. (see the paper by Lin and Lin
  442. (<a href=http://www.csie.ntu.edu.tw/~cjlin/papers/tanh.pdf>
  443. download paper here</a>).
  444. Polynomial kernels are ok but if a high degree is used,
  445. numerical difficulties tend to happen
  446. (thinking about dth power of (<1) goes to 0
  447. and (>1) goes to infinity).
  448. <p align="right">
  449. <a href="#_TOP">[Go Top]</a>
  450. <hr/>
  451. <a name="/Q4:_Training_and_prediction"></a>
  452. <a name="f405"><b>Q: Does libsvm have special treatments for linear SVM?</b></a>
  453. <br/>
  454. <p>
  455. No, libsvm solves linear/nonlinear SVMs by the
  456. same way.
  457. Some tricks may save training/testing time if the
  458. linear kernel is used,
  459. so libsvm is <b>NOT</b> particularly efficient for linear SVM,
  460. especially when
  461. C is large and
  462. the number of data is much larger
  463. than the number of attributes.
  464. You can either
  465. <ul>
  466. <li>
  467. Use small C only. We have shown in the following paper
  468. that after C is larger than a certain threshold,
  469. the decision function is the same.
  470. <p>
  471. <a href="http://guppy.mpe.nus.edu.sg/~mpessk/">S. S. Keerthi</a>
  472. and
  473. <B>C.-J. Lin</B>.
  474. <A HREF="papers/limit.ps.gz">
  475. Asymptotic behaviors of support vector machines with
  476. Gaussian kernel
  477. </A>
  478. .
  479. <I><A HREF="http://mitpress.mit.edu/journal-home.tcl?issn=08997667">Neural Computation</A></I>, 15(2003), 1667-1689.
  480. <li>
  481. Check <a href=http://www.csie.ntu.edu.tw/~cjlin/liblinear>liblinear</a>,
  482. which is designed for large-scale linear classification.
  483. More details can be found in the following study:
  484. <p>
  485. C.-J. Lin, R. C. Weng, and S. S. Keerthi.
  486. <a href=../papers/logistic.pdf>
  487. Trust region Newton method for large-scale logistic
  488. regression</a>.
  489. Technical report, 2007. A short version appears
  490. in <a href=http://oregonstate.edu/conferences/icml2007/>ICML 2007</a>.<br>
  491. </ul>
  492. <p> Please also see our <a href=../papers/guide/guide.pdf>SVM guide</a>
  493. on the discussion of using RBF and linear
  494. kernels.
  495. <p align="right">
  496. <a href="#_TOP">[Go Top]</a>
  497. <hr/>
  498. <a name="/Q4:_Training_and_prediction"></a>
  499. <a name="f406"><b>Q: The number of free support vectors is large. What should I do?</b></a>
  500. <br/>
  501. <p>
  502. This usually happens when the data are overfitted.
  503. If attributes of your data are in large ranges,
  504. try to scale them. Then the region
  505. of appropriate parameters may be larger.
  506. Note that there is a scale program
  507. in libsvm.
  508. <p align="right">
  509. <a href="#_TOP">[Go Top]</a>
  510. <hr/>
  511. <a name="/Q4:_Training_and_prediction"></a>
  512. <a name="f407"><b>Q: Should I scale training and testing data in a similar way?</b></a>
  513. <br/>
  514. <p>
  515. Yes, you can do the following:
  516. <br> svm-scale -s scaling_parameters train_data > scaled_train_data
  517. <br> svm-scale -r scaling_parameters test_data > scaled_test_data
  518. <p align="right">
  519. <a href="#_TOP">[Go Top]</a>
  520. <hr/>
  521. <a name="/Q4:_Training_and_prediction"></a>
  522. <a name="f408"><b>Q: Does it make a big difference if I scale each attribute to [0,1] instead of [-1,1]?</b></a>
  523. <br/>
  524. <p>
  525. For the linear scaling method, if the RBF kernel is
  526. used and parameter selection is conducted, there
  527. is no difference. Assume Mi and mi are
  528. respectively the maximal and minimal values of the
  529. ith attribute. Scaling to [0,1] means
  530. <pre>
  531. x'=(x-mi)/(Mi-mi)
  532. </pre>
  533. For [-1,1],
  534. <pre>
  535. x''=2(x-mi)/(Mi-mi)-1.
  536. </pre>
  537. In the RBF kernel,
  538. <pre>
  539. x'-y'=(x-y)/(Mi-mi), x''-y''=2(x-y)/(Mi-mi).
  540. </pre>
  541. Hence, using (C,g) on the [0,1]-scaled data is the
  542. same as (C,g/2) on the [-1,1]-scaled data.
  543. <p> Though the performance is the same, the computational
  544. time may be different. For data with many zero entries,
  545. [0,1]-scaling keeps the sparsity of input data and hence
  546. may save the time.
  547. <p align="right">
  548. <a href="#_TOP">[Go Top]</a>
  549. <hr/>
  550. <a name="/Q4:_Training_and_prediction"></a>
  551. <a name="f409"><b>Q: The prediction rate is low. How could I improve it?</b></a>
  552. <br/>
  553. <p>
  554. Try to use the model selection tool grid.py in the python
  555. directory find
  556. out good parameters. To see the importance of model selection,
  557. please
  558. see my talk:
  559. <A HREF="http://www.csie.ntu.edu.tw/~cjlin/talks/freiburg.pdf">
  560. A practical guide to support vector
  561. classification
  562. </A>
  563. <p align="right">
  564. <a href="#_TOP">[Go Top]</a>
  565. <hr/>
  566. <a name="/Q4:_Training_and_prediction"></a>
  567. <a name="f410"><b>Q: My data are unbalanced. Could libsvm handle such problems?</b></a>
  568. <br/>
  569. <p>
  570. Yes, there is a -wi options. For example, if you use
  571. <p>
  572. svm-train -s 0 -c 10 -w1 1 -w-1 5 data_file
  573. <p>
  574. the penalty for class "-1" is larger.
  575. Note that this -w option is for C-SVC only.
  576. <p align="right">
  577. <a href="#_TOP">[Go Top]</a>
  578. <hr/>
  579. <a name="/Q4:_Training_and_prediction"></a>
  580. <a name="f411"><b>Q: What is the difference between nu-SVC and C-SVC?</b></a>
  581. <br/>
  582. <p>
  583. Basically they are the same thing but with different
  584. parameters. The range of C is from zero to infinity
  585. but nu is always between [0,1]. A nice property
  586. of nu is that it is related to the ratio of
  587. support vectors and the ratio of the training
  588. error.
  589. <p align="right">
  590. <a href="#_TOP">[Go Top]</a>
  591. <hr/>
  592. <a name="/Q4:_Training_and_prediction"></a>
  593. <a name="f412"><b>Q: The program keeps running (without showing any output). What should I do?</b></a>
  594. <br/>
  595. <p>
  596. You may want to check your data. Each training/testing
  597. data must be in one line. It cannot be separated.
  598. In addition, you have to remove empty lines.
  599. <p align="right">
  600. <a href="#_TOP">[Go Top]</a>
  601. <hr/>
  602. <a name="/Q4:_Training_and_prediction"></a>
  603. <a name="f413"><b>Q: The program keeps running (with output, i.e. many dots). What should I do?</b></a>
  604. <br/>
  605. <p>
  606. In theory libsvm guarantees to converge if the kernel
  607. matrix is positive semidefinite.
  608. After version 2.4 it can also handle non-PSD
  609. kernels such as the sigmoid (tanh).
  610. Therefore, this means you are
  611. handling ill-conditioned situations
  612. (e.g. too large/small parameters) so numerical
  613. difficulties occur.
  614. <p align="right">
  615. <a href="#_TOP">[Go Top]</a>
  616. <hr/>
  617. <a name="/Q4:_Training_and_prediction"></a>
  618. <a name="f414"><b>Q: The training time is too long. What should I do?</b></a>
  619. <br/>
  620. <p>
  621. For large problems, please specify enough cache size (i.e.,
  622. -m).
  623. Slow convergence may happen for some difficult cases (e.g. -c is large).
  624. You can try to use a looser stopping tolerance with -e.
  625. If that still doesn't work, you may want to train only a subset of the data.
  626. You can use the program subset.py in the directory "tools"
  627. to obtain a random subset.
  628. <p>
  629. If you are using polynomial kernels, please check the question on the pow() function.
  630. <p align="right">
  631. <a href="#_TOP">[Go Top]</a>
  632. <hr/>
  633. <a name="/Q4:_Training_and_prediction"></a>
  634. <a name="f415"><b>Q: How do I get the decision value(s)?</b></a>
  635. <br/>
  636. <p>
  637. We print out decision values for regression. For classification,
  638. we solve several binary SVMs for multi-class cases. You
  639. can obtain values by easily calling the subroutine
  640. svm_predict_values. Their corresponding labels
  641. can be obtained from svm_get_labels.
  642. Details are in
  643. README of libsvm package.
  644. <p>
  645. We do not recommend the following. But if you would
  646. like to get values for
  647. TWO-class classification with labels +1 and -1
  648. (note: +1 and -1 but not things like 5 and 10)
  649. in the easiest way, simply add
  650. <pre>
  651. printf("%f\n", dec_values[0]*model->label[0]);
  652. </pre>
  653. after the line
  654. <pre>
  655. svm_predict_values(model, x, dec_values);
  656. </pre>
  657. of the file svm.cpp.
  658. Positive (negative)
  659. decision values correspond to data predicted as +1 (-1).
  660. <p align="right">
  661. <a href="#_TOP">[Go Top]</a>
  662. <hr/>
  663. <a name="/Q4:_Training_and_prediction"></a>
  664. <a name="f4151"><b>Q: How do I get the distance between a point and the hyperplane?</b></a>
  665. <br/>
  666. <p>
  667. The distance is |decision_value| / |w|.
  668. We have |w|^2 = w^Tw = alpha^T Q alpha = 2*(dual_obj + sum alpha_i).
  669. Thus in svm.cpp please find the place
  670. where we calculate the dual objective value
  671. (i.e., the subroutine Solve())
  672. and add a statement to print w^Tw.
  673. <p align="right">
  674. <a href="#_TOP">[Go Top]</a>
  675. <hr/>
  676. <a name="/Q4:_Training_and_prediction"></a>
  677. <a name="f416"><b>Q: On 32-bit machines, if I use a large cache (i.e. large -m) on a linux machine, why sometimes I get "segmentation fault ?"</b></a>
  678. <br/>
  679. <p>
  680. On 32-bit machines, the maximum addressable
  681. memory is 4GB. The Linux kernel uses 3:1
  682. split which means user space is 3G and
  683. kernel space is 1G. Although there are
  684. 3G user space, the maximum dynamic allocation
  685. memory is 2G. So, if you specify -m near 2G,
  686. the memory will be exhausted. And svm-train
  687. will fail when it asks more memory.
  688. For more details, please read
  689. <a href=http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3BA164F6.BAFA4FB%40daimi.au.dk>
  690. this article</a>.
  691. <p>
  692. The easiest solution is to switch to a
  693. 64-bit machine.
  694. Otherwise, there are two ways to solve this. If your
  695. machine supports Intel's PAE (Physical Address
  696. Extension), you can turn on the option HIGHMEM64G
  697. in Linux kernel which uses 4G:4G split for
  698. kernel and user space. If you don't, you can
  699. try a software `tub' which can eliminate the 2G
  700. boundary for dynamic allocated memory. The `tub'
  701. is available at
  702. <a href=http://www.bitwagon.com/tub.html>http://www.bitwagon.com/tub.html</a>.
  703. <!--
  704. This may happen only when the cache is large, but each cached row is
  705. not large enough. <b>Note:</b> This problem is specific to
  706. gnu C library which is used in linux.
  707. The solution is as follows:
  708. <p>
  709. In our program we have malloc() which uses two methods
  710. to allocate memory from kernel. One is
  711. sbrk() and another is mmap(). sbrk is faster, but mmap
  712. has a larger address
  713. space. So malloc uses mmap only if the wanted memory size is larger
  714. than some threshold (default 128k).
  715. In the case where each row is not large enough (#elements < 128k/sizeof(float)) but we need a large cache ,
  716. the address space for sbrk can be exhausted. The solution is to
  717. lower the threshold to force malloc to use mmap
  718. and increase the maximum number of chunks to allocate
  719. with mmap.
  720. <p>
  721. Therefore, in the main program (i.e. svm-train.c) you want
  722. to have
  723. <pre>
  724. #include &lt;malloc.h&gt;
  725. </pre>
  726. and then in main():
  727. <pre>
  728. mallopt(M_MMAP_THRESHOLD, 32768);
  729. mallopt(M_MMAP_MAX,1000000);
  730. </pre>
  731. You can also set the environment variables instead
  732. of writing them in the program:
  733. <pre>
  734. $ M_MMAP_MAX=1000000 M_MMAP_THRESHOLD=32768 ./svm-train .....
  735. </pre>
  736. More information can be found by
  737. <pre>
  738. $ info libc "Malloc Tunable Parameters"
  739. </pre>
  740. -->
  741. <p align="right">
  742. <a href="#_TOP">[Go Top]</a>
  743. <hr/>
  744. <a name="/Q4:_Training_and_prediction"></a>
  745. <a name="f417"><b>Q: How do I disable screen output of svm-train and svm-predict ?</b></a>
  746. <br/>
  747. <p>
  748. Simply update svm.cpp:
  749. <pre>
  750. #if 1
  751. void info(char *fmt,...)
  752. </pre>
  753. to
  754. <pre>
  755. #if 0
  756. void info(char *fmt,...)
  757. </pre>
  758. <p align="right">
  759. <a href="#_TOP">[Go Top]</a>
  760. <hr/>
  761. <a name="/Q4:_Training_and_prediction"></a>
  762. <a name="f418"><b>Q: I would like to use my own kernel but find out that there are two subroutines for kernel evaluations: k_function() and kernel_function(). Which one should I modify ?</b></a>
  763. <br/>
  764. <p>
  765. The reason why we have two functions is as follows:
  766. For the RBF kernel exp(-g |xi - xj|^2), if we calculate
  767. xi - xj first and then the norm square, there are 3n operations.
  768. Thus we consider exp(-g (|xi|^2 - 2dot(xi,xj) +|xj|^2))
  769. and by calculating all |xi|^2 in the beginning,
  770. the number of operations is reduced to 2n.
  771. This is for the training. For prediction we cannot
  772. do this so a regular subroutine using that 3n operations is
  773. needed.
  774. The easiest way to have your own kernel is
  775. to put the same code in these two
  776. subroutines by replacing any kernel.
  777. <p align="right">
  778. <a href="#_TOP">[Go Top]</a>
  779. <hr/>
  780. <a name="/Q4:_Training_and_prediction"></a>
  781. <a name="f419"><b>Q: What method does libsvm use for multi-class SVM ? Why don't you use the "1-against-the rest" method ?</b></a>
  782. <br/>
  783. <p>
  784. It is one-against-one. We chose it after doing the following
  785. comparison:
  786. C.-W. Hsu and C.-J. Lin.
  787. <A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/multisvm.pdf">
  788. A comparison of methods
  789. for multi-class support vector machines
  790. </A>,
  791. <I>IEEE Transactions on Neural Networks</A></I>, 13(2002), 415-425.
  792. <p>
  793. "1-against-the rest" is a good method whose performance
  794. is comparable to "1-against-1." We do the latter
  795. simply because its training time is shorter.
  796. <p align="right">
  797. <a href="#_TOP">[Go Top]</a>
  798. <hr/>
  799. <a name="/Q4:_Training_and_prediction"></a>
  800. <a name="f420"><b>Q: After doing cross validation, why there is no model file outputted ?</b></a>
  801. <br/>
  802. <p>
  803. Cross validation is used for selecting good parameters.
  804. After finding them, you want to re-train the whole
  805. data without the -v option.
  806. <p align="right">
  807. <a href="#_TOP">[Go Top]</a>
  808. <hr/>
  809. <a name="/Q4:_Training_and_prediction"></a>
  810. <a name="f4201"><b>Q: Why my cross-validation results are different from those in the Practical Guide?</b></a>
  811. <br/>
  812. <p>
  813. Due to random partitions of
  814. the data, on different systems CV accuracy values
  815. may be different.
  816. <p align="right">
  817. <a href="#_TOP">[Go Top]</a>
  818. <hr/>
  819. <a name="/Q4:_Training_and_prediction"></a>
  820. <a name="f421"><b>Q: But on some systems CV accuracy is the same in several runs. How could I use different data partitions?</b></a>
  821. <br/>
  822. <p>
  823. If you use GNU C library,
  824. the default seed 1 is considered. Thus you always
  825. get the same result of running svm-train -v.
  826. To have different seeds, you can add the following code
  827. in svm-train.c:
  828. <pre>
  829. #include &lt;time.h&gt;
  830. </pre>
  831. and in the beginning of the subroutine do_cross_validation(),
  832. <pre>
  833. srand(time(0));
  834. </pre>
  835. <p align="right">
  836. <a href="#_TOP">[Go Top]</a>
  837. <hr/>
  838. <a name="/Q4:_Training_and_prediction"></a>
  839. <a name="f422"><b>Q: I would like to solve L2-loss SVM (i.e., error term is quadratic). How should I modify the code ?</b></a>
  840. <br/>
  841. <p>
  842. It is extremely easy. Taking c-svc for example, only two
  843. places of svm.cpp have to be changed.
  844. First, modify the following line of
  845. solve_c_svc from
  846. <pre>
  847. s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
  848. alpha, Cp, Cn, param->eps, si, param->shrinking);
  849. </pre>
  850. to
  851. <pre>
  852. s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
  853. alpha, INF, INF, param->eps, si, param->shrinking);
  854. </pre>
  855. Second, in the class of SVC_Q, declare C as
  856. a private variable:
  857. <pre>
  858. double C;
  859. </pre>
  860. In the constructor we assign it to param.C:
  861. <pre>
  862. this->C = param.C;
  863. </pre>
  864. Then in the subroutine get_Q, after the for loop, add
  865. <pre>
  866. if(i >= start && i < len)
  867. data[i] += 1/C;
  868. </pre>
  869. <p>
  870. 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:
  871. <pre>
  872. data[real_i] += 1/C;
  873. </pre>
  874. <p>
  875. For large linear L2-loss SVM, please use
  876. <a href=../liblinear>LIBLINEAR</a>.
  877. <p align="right">
  878. <a href="#_TOP">[Go Top]</a>
  879. <hr/>
  880. <a name="/Q4:_Training_and_prediction"></a>
  881. <a name="f424"><b>Q: How do I choose parameters for one-class svm as training data are in only one class?</b></a>
  882. <br/>
  883. <p>
  884. You have pre-specified true positive rate in mind and then search for
  885. parameters which achieve similar cross-validation accuracy.
  886. <p align="right">
  887. <a href="#_TOP">[Go Top]</a>
  888. <hr/>
  889. <a name="/Q4:_Training_and_prediction"></a>
  890. <a name="f427"><b>Q: Why the code gives NaN (not a number) results?</b></a>
  891. <br/>
  892. <p>
  893. This rarely happens, but few users reported the problem.
  894. It seems that their
  895. computers for training libsvm have the VPN client
  896. running. The VPN software has some bugs and causes this
  897. problem. Please try to close or disconnect the VPN client.
  898. <p align="right">
  899. <a href="#_TOP">[Go Top]</a>
  900. <hr/>
  901. <a name="/Q4:_Training_and_prediction"></a>
  902. <a name="f428"><b>Q: Why on windows sometimes grid.py fails?</b></a>
  903. <br/>
  904. <p>
  905. This problem shouldn't happen after version
  906. 2.85. If you are using earlier versions,
  907. please download the latest one.
  908. <!--
  909. <p>
  910. If you are using earlier
  911. versions, the error message is probably
  912. <pre>
  913. Traceback (most recent call last):
  914. File "grid.py", line 349, in ?
  915. main()
  916. File "grid.py", line 344, in main
  917. redraw(db)
  918. File "grid.py", line 132, in redraw
  919. gnuplot.write("set term windows\n")
  920. IOError: [Errno 22] Invalid argument
  921. </pre>
  922. <p>Please try to close gnuplot windows and rerun.
  923. If the problem still occurs, comment the following
  924. two lines in grid.py by inserting "#" in the beginning:
  925. <pre>
  926. redraw(db)
  927. redraw(db,1)
  928. </pre>
  929. Then you get accuracy only but not cross validation contours.
  930. -->
  931. <p align="right">
  932. <a href="#_TOP">[Go Top]</a>
  933. <hr/>
  934. <a name="/Q4:_Training_and_prediction"></a>
  935. <a name="f429"><b>Q: Why grid.py/easy.py sometimes generates the following warning message?</b></a>
  936. <br/>
  937. <pre>
  938. Warning: empty z range [62.5:62.5], adjusting to [61.875:63.125]
  939. Notice: cannot contour non grid data!
  940. </pre>
  941. <p>Nothing is wrong and please disregard the
  942. message. It is from gnuplot when drawing
  943. the contour.
  944. <p align="right">
  945. <a href="#_TOP">[Go Top]</a>
  946. <hr/>
  947. <a name="/Q4:_Training_and_prediction"></a>
  948. <a name="f430"><b>Q: Why the sign of predicted labels and decision values are sometimes reversed?</b></a>
  949. <br/>
  950. <p>Nothing is wrong. Very likely you have two labels +1/-1 and the first instance in your data
  951. has -1.
  952. Think about the case of labels +5/+10. Since
  953. SVM needs to use +1/-1, internally
  954. we map +5/+10 to +1/-1 according to which
  955. label appears first.
  956. Hence a positive decision value implies
  957. that we should predict the "internal" +1,
  958. which may not be the +1 in the input file.
  959. <p align="right">
  960. <a href="#_TOP">[Go Top]</a>
  961. <hr/>
  962. <a name="/Q5:_Probability_outputs"></a>
  963. <a name="f425"><b>Q: Why training a probability model (i.e., -b 1) takes longer time</b></a>
  964. <br/>
  965. <p>
  966. To construct this probability model, we internally conduct a
  967. cross validation, which is more time consuming than
  968. a regular training.
  969. Hence, in general you do parameter selection first without
  970. -b 1. You only use -b 1 when good parameters have been
  971. selected. In other words, you avoid using -b 1 and -v
  972. together.
  973. <p align="right">
  974. <a href="#_TOP">[Go Top]</a>
  975. <hr/>
  976. <a name="/Q5:_Probability_outputs"></a>
  977. <a name="f426"><b>Q: Why using the -b option does not give me better accuracy?</b></a>
  978. <br/>
  979. <p>
  980. There is absolutely no reason the probability outputs guarantee
  981. you better accuracy. The main purpose of this option is
  982. to provide you the probability estimates, but not to boost
  983. prediction accuracy. From our experience,
  984. after proper parameter selections, in general with
  985. and without -b have similar accuracy. Occasionally there
  986. are some differences.
  987. It is not recommended to compare the two under
  988. just a fixed parameter
  989. set as more differences will be observed.
  990. <p align="right">
  991. <a href="#_TOP">[Go Top]</a>
  992. <hr/>
  993. <a name="/Q5:_Probability_outputs"></a>
  994. <a name="f427"><b>Q: Why using svm-predict -b 0 and -b 1 gives different accuracy values?</b></a>
  995. <br/>
  996. <p>
  997. Let's just consider two-class classification here. After probability information is obtained in training,
  998. we do not have
  999. <p>
  1000. prob > = 0.5 if and only if decision value >= 0.
  1001. <p>
  1002. So predictions may be different with -b 0 and 1.
  1003. <p align="right">
  1004. <a href="#_TOP">[Go Top]</a>
  1005. <hr/>
  1006. <a name="/Q6:_Graphic_interface"></a>
  1007. <a name="f501"><b>Q: How can I save images drawn by svm-toy?</b></a>
  1008. <br/>
  1009. <p>
  1010. For Microsoft windows, first press the "print screen" key on the keyboard.
  1011. Open "Microsoft Paint"
  1012. (included in Windows)
  1013. and press "ctrl-v." Then you can clip
  1014. the part of picture which you want.
  1015. For X windows, you can
  1016. use the program "xv" or "import" to grab the picture of the svm-toy window.
  1017. <p align="right">
  1018. <a href="#_TOP">[Go Top]</a>
  1019. <hr/>
  1020. <a name="/Q6:_Graphic_interface"></a>
  1021. <a name="f502"><b>Q: I press the "load" button to load data points but why svm-toy does not draw them ?</b></a>
  1022. <br/>
  1023. <p>
  1024. The program svm-toy assumes both attributes (i.e. x-axis and y-axis
  1025. values) are in (0,1). Hence you want to scale your
  1026. data to between a small positive number and
  1027. a number less than but very close to 1.
  1028. Moreover, class labels must be 1, 2, or 3
  1029. (not 1.0, 2.0 or anything else).
  1030. <p align="right">
  1031. <a href="#_TOP">[Go Top]</a>
  1032. <hr/>
  1033. <a name="/Q6:_Graphic_interface"></a>
  1034. <a name="f503"><b>Q: I would like svm-toy to handle more than three classes of data, what should I do ?</b></a>
  1035. <br/>
  1036. <p>
  1037. Taking windows/svm-toy.cpp as an example, you need to
  1038. modify it and the difference
  1039. from the original file is as the following: (for five classes of
  1040. data)
  1041. <pre>
  1042. 30,32c30
  1043. < RGB(200,0,200),
  1044. < RGB(0,160,0),
  1045. < RGB(160,0,0)
  1046. ---
  1047. > RGB(200,0,200)
  1048. 39c37
  1049. < HBRUSH brush1, brush2, brush3, brush4, brush5;
  1050. ---
  1051. > HBRUSH brush1, brush2, brush3;
  1052. 113,114d110
  1053. < brush4 = CreateSolidBrush(colors[7]);
  1054. < brush5 = CreateSolidBrush(colors[8]);
  1055. 155,157c151
  1056. < else if(v==3) return brush3;
  1057. < else if(v==4) return brush4;
  1058. < else return brush5;
  1059. ---
  1060. > else return brush3;
  1061. 325d318
  1062. < int colornum = 5;
  1063. 327c320
  1064. < svm_node *x_space = new svm_node[colornum * prob.l];
  1065. ---
  1066. > svm_node *x_space = new svm_node[3 * prob.l];
  1067. 333,338c326,331
  1068. < x_space[colornum * i].index = 1;
  1069. < x_space[colornum * i].value = q->x;
  1070. < x_space[colornum * i + 1].index = 2;
  1071. < x_space[colornum * i + 1].value = q->y;
  1072. < x_space[colornum * i + 2].index = -1;
  1073. < prob.x[i] = &x_space[colornum * i];
  1074. ---
  1075. > x_space[3 * i].index = 1;
  1076. > x_space[3 * i].value = q->x;
  1077. > x_space[3 * i + 1].index = 2;
  1078. > x_space[3 * i + 1].value = q->y;
  1079. > x_space[3 * i + 2].index = -1;
  1080. > prob.x[i] = &x_space[3 * i];
  1081. 397c390
  1082. < if(current_value > 5) current_value = 1;
  1083. ---
  1084. > if(current_value > 3) current_value = 1;
  1085. </pre>
  1086. <p align="right">
  1087. <a href="#_TOP">[Go Top]</a>
  1088. <hr/>
  1089. <a name="/Q7:_Java_version_of_libsvm"></a>
  1090. <a name="f601"><b>Q: What is the difference between Java version and C++ version of libsvm?</b></a>
  1091. <br/>
  1092. <p>
  1093. They are the same thing. We just rewrote the C++ code
  1094. in Java.
  1095. <p align="right">
  1096. <a href="#_TOP">[Go Top]</a>
  1097. <hr/>
  1098. <a name="/Q7:_Java_version_of_libsvm"></a>
  1099. <a name="f602"><b>Q: Is the Java version significantly slower than the C++ version?</b></a>
  1100. <br/>
  1101. <p>
  1102. This depends on the VM you used. We have seen good
  1103. VM which leads the Java version to be quite competitive with
  1104. the C++ code. (though still slower)
  1105. <p align="right">
  1106. <a href="#_TOP">[Go Top]</a>
  1107. <hr/>
  1108. <a name="/Q7:_Java_version_of_libsvm"></a>
  1109. <a name="f603"><b>Q: While training I get the following error message: java.lang.OutOfMemoryError. What is wrong?</b></a>
  1110. <br/>
  1111. <p>
  1112. You should try to increase the maximum Java heap size.
  1113. For example,
  1114. <pre>
  1115. java -Xmx2048m -classpath libsvm.jar svm_train ...
  1116. </pre>
  1117. sets the maximum heap size to 2048M.
  1118. <p align="right">
  1119. <a href="#_TOP">[Go Top]</a>
  1120. <hr/>
  1121. <a name="/Q7:_Java_version_of_libsvm"></a>
  1122. <a name="f604"><b>Q: Why you have the main source file svm.m4 and then transform it to svm.java?</b></a>
  1123. <br/>
  1124. <p>
  1125. Unlike C, Java does not have a preprocessor built-in.
  1126. However, we need some macros (see first 3 lines of svm.m4).
  1127. </ul>
  1128. <p align="right">
  1129. <a href="#_TOP">[Go Top]</a>
  1130. <hr/>
  1131. <a name="/Q8:_Python_interface"></a>
  1132. <a name="f702"><b>Q: On MS windows, why does python fail to load the pyd file?</b></a>
  1133. <br/>
  1134. <p>
  1135. It seems the pyd file is version dependent. So far we haven't
  1136. found out a good solution. Please email us if you have any
  1137. good suggestions.
  1138. <p align="right">
  1139. <a href="#_TOP">[Go Top]</a>
  1140. <hr/>
  1141. <a name="/Q8:_Python_interface"></a>
  1142. <a name="f703"><b>Q: How to modify the python interface on MS windows and rebuild the .pyd file ?</b></a>
  1143. <br/>
  1144. <p>
  1145. To modify the interface, follow the instructions given in
  1146. <a href=
  1147. http://www.swig.org/Doc1.3/Python.html#Python>
  1148. http://www.swig.org/Doc1.3/Python.html#Python
  1149. </a>
  1150. <p>
  1151. If you just want to build .pyd for a different python version,
  1152. after libsvm 2.5, you can easily use the file Makefile.win.
  1153. See details in README.
  1154. Alternatively, you can use Visual C++. Here is
  1155. the example using Visual Studio .Net 2005:
  1156. <ol>
  1157. <li>Create a Win32 DLL project and set (in Project->$Project_Name
  1158. Properties...->Configuration) to "Release."
  1159. About how to create a new dynamic link library, please refer to
  1160. <a href=http://msdn2.microsoft.com/en-us/library/ms235636(VS.80).aspx>http://msdn2.microsoft.com/en-us/library/ms235636(VS.80).aspx</a>
  1161. <li> Add svm.cpp, svmc_wrap.c, pythonXX.lib to your project.
  1162. <li> Add the directories containing Python.h and svm.h to the Additional
  1163. Include Directories(in Project->$Project_Name
  1164. Properties...->C/C++->General)
  1165. <li> Add __WIN32__ to Preprocessor definitions (in
  1166. Project->$Project_Name Properties...->C/C++->Preprocessor)
  1167. <li> Set Create/Use Precompiled Header to Not Using Precompiled Headers
  1168. (in Project->$Project_Name Properties...->C/C++->Precompiled Headers)
  1169. <li> Build the DLL.
  1170. <li> You may have to rename .dll to .pyd
  1171. </ol>
  1172. <!--
  1173. There do exist work arounds, however. In
  1174. http://aspn.activestate.com/ASPN/Mail/Message/python-list/983252
  1175. they presented a solution: 1) find the version of python in the
  1176. registry 2) perform LoadLibrary("pythonxx.dll") and 3) resolve the
  1177. reference to functions through GetProcAddress. It is said that SWIG
  1178. may help on this.
  1179. http://mailman.cs.uchicago.edu/pipermail/swig/2001-July/002744.html
  1180. presented a similar example.
  1181. -->
  1182. <p align="right">
  1183. <a href="#_TOP">[Go Top]</a>
  1184. <hr/>
  1185. <a name="/Q8:_Python_interface"></a>
  1186. <a name="f704"><b>Q: Except the python-C++ interface provided, could I use Jython to call libsvm ?</b></a>
  1187. <br/>
  1188. <p> Yes, here are some examples:
  1189. <pre>
  1190. $ export CLASSPATH=$CLASSPATH:~/libsvm-2.4/java/libsvm.jar
  1191. $ ./jython
  1192. Jython 2.1a3 on java1.3.0 (JIT: jitc)
  1193. Type "copyright", "credits" or "license" for more information.
  1194. >>> from libsvm import *
  1195. >>> dir()
  1196. ['__doc__', '__name__', 'svm', 'svm_model', 'svm_node', 'svm_parameter',
  1197. 'svm_problem']
  1198. >>> x1 = [svm_node(index=1,value=1)]
  1199. >>> x2 = [svm_node(index=1,value=-1)]
  1200. >>> param = svm_parameter(svm_type=0,kernel_type=2,gamma=1,cache_size=40,eps=0.001,C=1,nr_weight=0,shrinking=1)
  1201. >>> prob = svm_problem(l=2,y=[1,-1],x=[x1,x2])
  1202. >>> model = svm.svm_train(prob,param)
  1203. *
  1204. optimization finished, #iter = 1
  1205. nu = 1.0
  1206. obj = -1.018315639346838, rho = 0.0
  1207. nSV = 2, nBSV = 2
  1208. Total nSV = 2
  1209. >>> svm.svm_predict(model,x1)
  1210. 1.0
  1211. >>> svm.svm_predict(model,x2)
  1212. -1.0
  1213. >>> svm.svm_save_model("test.model",model)
  1214. </pre>
  1215. <p align="right">
  1216. <a href="#_TOP">[Go Top]</a>
  1217. <hr/>
  1218. <a name="/Q8:_Python_interface"></a>
  1219. <a name="f705"><b>Q: How could I install the python interface on Mac OS? </b></a>
  1220. <br/>
  1221. <p> Instead of
  1222. LDFLAGS = -shared
  1223. in the Makefile, you need
  1224. <pre>
  1225. LDFLAGS = -framework Python -bundle
  1226. </pre>
  1227. <!--
  1228. LDFLAGS = -bundle -flat_namespace -undefined suppress
  1229. -->
  1230. The problem is that under MacOs there is no "shared libraries."
  1231. Instead they use "dynamic libraries."
  1232. <p align="right">
  1233. <a href="#_TOP">[Go Top]</a>
  1234. <hr/>
  1235. <a name="/Q8:_Python_interface"></a>
  1236. <a name="f706"><b>Q: I typed "make" on a unix system, but it says "Python.h: No such file or directory?"</b></a>
  1237. <br/>
  1238. <p>
  1239. Even though you may have python on your
  1240. system, very likely
  1241. python development tools
  1242. are not installed. Please check with
  1243. your system administrator.
  1244. <p align="right">
  1245. <a href="#_TOP">[Go Top]</a>
  1246. <hr/>
  1247. <a name="/Q9:_MATLAB_interface"></a>
  1248. <a name="f801"><b>Q: I compile the MATLAB interface without problem, but why errors occur while running it?</b></a>
  1249. <br/>
  1250. <p>
  1251. Your compiler version may not be supported/compatible for MATLAB.
  1252. Please check <a href=http://www.mathworks.com/support/compilers/current_release>this MATLAB page</a> first and then specify the version
  1253. number. For example, if g++ 3.3 is supported, replace
  1254. <pre>
  1255. CXX = g++
  1256. </pre>
  1257. in the Makefile with
  1258. <pre>
  1259. CXX = g++-3.3
  1260. </pre>
  1261. <p align="right">
  1262. <a href="#_TOP">[Go Top]</a>
  1263. <hr/>
  1264. <a name="/Q9:_MATLAB_interface"></a>
  1265. <a name="f802"><b>Q: Does the MATLAB interface provide a function to do scaling?</b></a>
  1266. <br/>
  1267. <p>
  1268. It is extremely easy to do scaling under MATLAB.
  1269. The following one-line code scale each feature to the range
  1270. of [0.1]:
  1271. <pre>
  1272. (data - repmat(min(data,[],1),size(data,1),1))./(repmat(max(data,[],1)-min(data,[],1),size(data,1),1))
  1273. </pre>
  1274. <p align="right">
  1275. <a href="#_TOP">[Go Top]</a>
  1276. <hr/>
  1277. <a name="/Q9:_MATLAB_interface"></a>
  1278. <a name="f803"><b>Q: How could I use MATLAB interface for parameter selection?</b></a>
  1279. <br/>
  1280. <p>
  1281. One can do this by a simple loop.
  1282. See the following example:
  1283. <pre>
  1284. bestcv = 0;
  1285. for log2c = -1:3,
  1286. for log2g = -4:1,
  1287. cmd = ['-v 5 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
  1288. cv = svmtrain(heart_scale_label, heart_scale_inst, cmd);
  1289. if (cv >= bestcv),
  1290. bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
  1291. end
  1292. fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
  1293. end
  1294. end
  1295. </pre>
  1296. <p align="right">
  1297. <a href="#_TOP">[Go Top]</a>
  1298. <hr/>
  1299. <a name="/Q9:_MATLAB_interface"></a>
  1300. <a name="f804"><b>Q: How could I generate the primal variable w of linear SVM?</b></a>
  1301. <br/>
  1302. <p>
  1303. Assume you have two labels -1 and +1.
  1304. After obtaining the model from calling svmtrain,
  1305. do the following to have w and b:
  1306. <pre>
  1307. w = model.SVs' * model.sv_coef;
  1308. b = -model.rho;
  1309. if model.Label(1) == -1
  1310. w = -w;
  1311. b = -b;
  1312. end
  1313. </pre>
  1314. <p align="right">
  1315. <a href="#_TOP">[Go Top]</a>
  1316. <hr/>
  1317. <a name="/Q9:_MATLAB_interface"></a>
  1318. <a name="f805"><b>Q: Is there an OCTAVE interface for libsvm?</b></a>
  1319. <br/>
  1320. <p>
  1321. Yes, after libsvm 2.86, the matlab interface
  1322. works on OCTAVE as well. Please type
  1323. <pre>
  1324. make octave
  1325. </pre>
  1326. for installation.
  1327. <p align="right">
  1328. <a href="#_TOP">[Go Top]</a>
  1329. <hr/>
  1330. <p align="middle">
  1331. <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm">LIBSVM home page</a>
  1332. </p>
  1333. </body>
  1334. </html>