You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

FAQ.html 83 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166
  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. Tue, 20 Oct 2015 13:43:40 GMT
  10. <class="categories">
  11. <li><a
  12. href="#_TOP">All Questions</a>(84)</li>
  13. <ul><b>
  14. <li><a
  15. href="#/Q01:_Some_sample_uses_of_libsvm">Q01:_Some_sample_uses_of_libsvm</a>(2)</li>
  16. <li><a
  17. href="#/Q02:_Installation_and_running_the_program">Q02:_Installation_and_running_the_program</a>(13)</li>
  18. <li><a
  19. href="#/Q03:_Data_preparation">Q03:_Data_preparation</a>(7)</li>
  20. <li><a
  21. href="#/Q04:_Training_and_prediction">Q04:_Training_and_prediction</a>(29)</li>
  22. <li><a
  23. href="#/Q05:_Cross_validation_and_parameter_selection">Q05:_Cross_validation_and_parameter_selection</a>(9)</li>
  24. <li><a
  25. href="#/Q06:_Probability_outputs">Q06:_Probability_outputs</a>(3)</li>
  26. <li><a
  27. href="#/Q07:_Graphic_interface">Q07:_Graphic_interface</a>(3)</li>
  28. <li><a
  29. href="#/Q08:_Java_version_of_libsvm">Q08:_Java_version_of_libsvm</a>(4)</li>
  30. <li><a
  31. href="#/Q09:_Python_interface">Q09:_Python_interface</a>(1)</li>
  32. <li><a
  33. href="#/Q10:_MATLAB_OCTAVE_interface">Q10:_MATLAB_OCTAVE_interface</a>(13)</li>
  34. </b></ul>
  35. </li>
  36. <ul><ul class="headlines">
  37. <li class="headlines_item"><a href="#faq101">Some courses which have used libsvm as a tool</a></li>
  38. <li class="headlines_item"><a href="#faq102">Some applications/tools which have used libsvm </a></li>
  39. <li class="headlines_item"><a href="#f201">Where can I find documents/videos of libsvm ?</a></li>
  40. <li class="headlines_item"><a href="#f202">Where are change log and earlier versions?</a></li>
  41. <li class="headlines_item"><a href="#f203">How to cite LIBSVM?</a></li>
  42. <li class="headlines_item"><a href="#f204">I would like to use libsvm in my software. Is there any license problem?</a></li>
  43. <li class="headlines_item"><a href="#f205">Is there a repository of additional tools based on libsvm?</a></li>
  44. <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>
  45. <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>
  46. <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>
  47. <li class="headlines_item"><a href="#f209">What is the difference between "." and "*" outputed during training? </a></li>
  48. <li class="headlines_item"><a href="#f210">Why occasionally the program (including MATLAB or other interfaces) crashes and gives a segmentation fault?</a></li>
  49. <li class="headlines_item"><a href="#f211">How to build a dynamic library (.dll file) on MS windows?</a></li>
  50. <li class="headlines_item"><a href="#f212">On some systems (e.g., Ubuntu), compiling LIBSVM gives many warning messages. Is this a problem and how to disable the warning message?</a></li>
  51. <li class="headlines_item"><a href="#f213">In LIBSVM, why you don't use certain C/C++ library functions to make the code shorter?</a></li>
  52. <li class="headlines_item"><a href="#f301">Why sometimes not all attributes of a data appear in the training/model files ?</a></li>
  53. <li class="headlines_item"><a href="#f302">What if my data are non-numerical ?</a></li>
  54. <li class="headlines_item"><a href="#f303">Why do you consider sparse format ? Will the training of dense data be much slower ?</a></li>
  55. <li class="headlines_item"><a href="#f304">Why sometimes the last line of my data is not read by svm-train?</a></li>
  56. <li class="headlines_item"><a href="#f305">Is there a program to check if my data are in the correct format?</a></li>
  57. <li class="headlines_item"><a href="#f306">May I put comments in data files?</a></li>
  58. <li class="headlines_item"><a href="#f307">How to convert other data formats to LIBSVM format?</a></li>
  59. <li class="headlines_item"><a href="#f401">The output of training C-SVM is like the following. What do they mean?</a></li>
  60. <li class="headlines_item"><a href="#f402">Can you explain more about the model file?</a></li>
  61. <li class="headlines_item"><a href="#f403">Should I use float or double to store numbers in the cache ?</a></li>
  62. <li class="headlines_item"><a href="#f405">Does libsvm have special treatments for linear SVM?</a></li>
  63. <li class="headlines_item"><a href="#f406">The number of free support vectors is large. What should I do?</a></li>
  64. <li class="headlines_item"><a href="#f407">Should I scale training and testing data in a similar way?</a></li>
  65. <li class="headlines_item"><a href="#f4071">On windows sometimes svm-scale.exe generates some non-ASCII data not good for training/prediction?</a></li>
  66. <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>
  67. <li class="headlines_item"><a href="#f409">The prediction rate is low. How could I improve it?</a></li>
  68. <li class="headlines_item"><a href="#f410">My data are unbalanced. Could libsvm handle such problems?</a></li>
  69. <li class="headlines_item"><a href="#f411">What is the difference between nu-SVC and C-SVC?</a></li>
  70. <li class="headlines_item"><a href="#f412">The program keeps running (without showing any output). What should I do?</a></li>
  71. <li class="headlines_item"><a href="#f413">The program keeps running (with output, i.e. many dots). What should I do?</a></li>
  72. <li class="headlines_item"><a href="#f414">The training time is too long. What should I do?</a></li>
  73. <li class="headlines_item"><a href="#f4141">Does shrinking always help?</a></li>
  74. <li class="headlines_item"><a href="#f415">How do I get the decision value(s)?</a></li>
  75. <li class="headlines_item"><a href="#f4151">How do I get the distance between a point and the hyperplane?</a></li>
  76. <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>
  77. <li class="headlines_item"><a href="#f417">How do I disable screen output of svm-train?</a></li>
  78. <li class="headlines_item"><a href="#f418">I would like to use my own kernel. Any example? In svm.cpp, there are two subroutines for kernel evaluations: k_function() and kernel_function(). Which one should I modify ?</a></li>
  79. <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>
  80. <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>
  81. <li class="headlines_item"><a href="#f425">In one-class SVM, parameter nu should be an upper bound of the training error rate. Why sometimes I get a training error rate bigger than nu?</a></li>
  82. <li class="headlines_item"><a href="#f427">Why the code gives NaN (not a number) results?</a></li>
  83. <li class="headlines_item"><a href="#f430">Why the sign of predicted labels and decision values are sometimes reversed?</a></li>
  84. <li class="headlines_item"><a href="#f431">I don't know class labels of test data. What should I put in the first column of the test file?</a></li>
  85. <li class="headlines_item"><a href="#f432">How can I use OpenMP to parallelize LIBSVM on a multicore/shared-memory computer?</a></li>
  86. <li class="headlines_item"><a href="#f433">How could I know which training instances are support vectors?</a></li>
  87. <li class="headlines_item"><a href="#f434">Why sv_indices (indices of support vectors) are not stored in the saved model file?</a></li>
  88. <li class="headlines_item"><a href="#f501">After doing cross validation, why there is no model file outputted ?</a></li>
  89. <li class="headlines_item"><a href="#f502">Why my cross-validation results are different from those in the Practical Guide?</a></li>
  90. <li class="headlines_item"><a href="#f503">On some systems CV accuracy is the same in several runs. How could I use different data partitions? In other words, how do I set random seed in LIBSVM?</a></li>
  91. <li class="headlines_item"><a href="#f504">Why on windows sometimes grid.py fails?</a></li>
  92. <li class="headlines_item"><a href="#f505">Why grid.py/easy.py sometimes generates the following warning message?</a></li>
  93. <li class="headlines_item"><a href="#f506">How do I choose the kernel?</a></li>
  94. <li class="headlines_item"><a href="#f507">How does LIBSVM perform parameter selection for multi-class problems? </a></li>
  95. <li class="headlines_item"><a href="#f508">How do I choose parameters for one-class SVM as training data are in only one class?</a></li>
  96. <li class="headlines_item"><a href="#f509">Instead of grid.py, what if I would like to conduct parameter selection using other programmin languages?</a></li>
  97. <li class="headlines_item"><a href="#f425">Why training a probability model (i.e., -b 1) takes a longer time?</a></li>
  98. <li class="headlines_item"><a href="#f426">Why using the -b option does not give me better accuracy?</a></li>
  99. <li class="headlines_item"><a href="#f427">Why using svm-predict -b 0 and -b 1 gives different accuracy values?</a></li>
  100. <li class="headlines_item"><a href="#f501">How can I save images drawn by svm-toy?</a></li>
  101. <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>
  102. <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>
  103. <li class="headlines_item"><a href="#f601">What is the difference between Java version and C++ version of libsvm?</a></li>
  104. <li class="headlines_item"><a href="#f602">Is the Java version significantly slower than the C++ version?</a></li>
  105. <li class="headlines_item"><a href="#f603">While training I get the following error message: java.lang.OutOfMemoryError. What is wrong?</a></li>
  106. <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>
  107. <li class="headlines_item"><a href="#f704">Except the python-C++ interface provided, could I use Jython to call libsvm ?</a></li>
  108. <li class="headlines_item"><a href="#f801">I compile the MATLAB interface without problem, but why errors occur while running it?</a></li>
  109. <li class="headlines_item"><a href="#f8011">On 64bit Windows I compile the MATLAB interface without problem, but why errors occur while running it?</a></li>
  110. <li class="headlines_item"><a href="#f802">Does the MATLAB interface provide a function to do scaling?</a></li>
  111. <li class="headlines_item"><a href="#f803">How could I use MATLAB interface for parameter selection?</a></li>
  112. <li class="headlines_item"><a href="#f8031">I use MATLAB parallel programming toolbox on a multi-core environment for parameter selection. Why the program is even slower?</a></li>
  113. <li class="headlines_item"><a href="#f8032">How to use LIBSVM with OpenMP under MATLAB/Octave?</a></li>
  114. <li class="headlines_item"><a href="#f804">How could I generate the primal variable w of linear SVM?</a></li>
  115. <li class="headlines_item"><a href="#f805">Is there an OCTAVE interface for libsvm?</a></li>
  116. <li class="headlines_item"><a href="#f806">How to handle the name conflict between svmtrain in the libsvm matlab interface and that in MATLAB bioinformatics toolbox?</a></li>
  117. <li class="headlines_item"><a href="#f807">On Windows I got an error message "Invalid MEX-file: Specific module not found" when running the pre-built MATLAB interface in the windows sub-directory. What should I do?</a></li>
  118. <li class="headlines_item"><a href="#f808">LIBSVM supports 1-vs-1 multi-class classification. If instead I would like to use 1-vs-rest, how to implement it using MATLAB interface?</a></li>
  119. <li class="headlines_item"><a href="#f809">I tried to install matlab interface on mac, but failed. What should I do?</a></li>
  120. <li class="headlines_item"><a href="#f810">I tried to install octave interface on windows, but failed. What should I do?</a></li>
  121. </ul></ul>
  122. <hr size="5" noshade />
  123. <p/>
  124. <a name="/Q01:_Some_sample_uses_of_libsvm"></a>
  125. <a name="faq101"><b>Q: Some courses which have used libsvm as a tool</b></a>
  126. <br/>
  127. <ul>
  128. <li><a href=http://lmb.informatik.uni-freiburg.de/lectures/svm_seminar/>Institute for Computer Science,
  129. Faculty of Applied Science, University of Freiburg, Germany
  130. </a>
  131. <li> <a href=http://www.cs.vu.nl/~elena/ml.html>
  132. Division of Mathematics and Computer Science.
  133. Faculteit der Exacte Wetenschappen
  134. Vrije Universiteit, The Netherlands. </a>
  135. <li>
  136. <a href=http://www.cae.wisc.edu/~ece539/matlab/>
  137. Electrical and Computer Engineering Department,
  138. University of Wisconsin-Madison
  139. </a>
  140. <li>
  141. <a href=http://www.hpl.hp.com/personal/Carl_Staelin/cs236601/project.html>
  142. Technion (Israel Institute of Technology), Israel.
  143. <li>
  144. <a href=http://www.cise.ufl.edu/~fu/learn.html>
  145. Computer and Information Sciences Dept., University of Florida</a>
  146. <li>
  147. <a href=http://www.uonbi.ac.ke/acad_depts/ics/course_material/machine_learning/ML_and_DM_Resources.html>
  148. The Institute of Computer Science,
  149. University of Nairobi, Kenya.</a>
  150. <li>
  151. <a href=http://cerium.raunvis.hi.is/~tpr/courseware/svm/hugbunadur.html>
  152. Applied Mathematics and Computer Science, University of Iceland.
  153. <li>
  154. <a href=http://chicago05.mlss.cc/tiki/tiki-read_article.php?articleId=2>
  155. SVM tutorial in machine learning
  156. summer school, University of Chicago, 2005.
  157. </a>
  158. </ul>
  159. <p align="right">
  160. <a href="#_TOP">[Go Top]</a>
  161. <hr/>
  162. <a name="/Q01:_Some_sample_uses_of_libsvm"></a>
  163. <a name="faq102"><b>Q: Some applications/tools which have used libsvm </b></a>
  164. <br/>
  165. (and maybe liblinear).
  166. <ul>
  167. <li>
  168. <a href=http://people.csail.mit.edu/jjl/libpmk/>LIBPMK: A Pyramid Match Toolkit</a>
  169. </li>
  170. <li><a href=http://maltparser.org/>Maltparser</a>:
  171. a system for data-driven dependency parsing
  172. </li>
  173. <li>
  174. <a href=http://www.pymvpa.org/>PyMVPA: python tool for classifying neuroimages</a>
  175. </li>
  176. <li>
  177. <a href=http://solpro.proteomics.ics.uci.edu/>
  178. SOLpro: protein solubility predictor
  179. </a>
  180. </li>
  181. <li>
  182. <a href=http://bdval.campagnelab.org>
  183. BDVal</a>: biomarker discovery in high-throughput datasets.
  184. </li>
  185. <li><a href=http://johel.m.free.fr/demo_045.htm>
  186. Realtime object recognition</a>
  187. </li>
  188. <li><a href=http://scikit-learn.sourceforge.net/>
  189. scikits.learn: machine learning in Python</a>
  190. </li>
  191. </ul>
  192. <p align="right">
  193. <a href="#_TOP">[Go Top]</a>
  194. <hr/>
  195. <a name="/Q02:_Installation_and_running_the_program"></a>
  196. <a name="f201"><b>Q: Where can I find documents/videos of libsvm ?</b></a>
  197. <br/>
  198. <p>
  199. <ul>
  200. <li>
  201. Official implementation document:
  202. <br>
  203. C.-C. Chang and
  204. C.-J. Lin.
  205. LIBSVM
  206. : a library for support vector machines.
  207. ACM Transactions on Intelligent
  208. Systems and Technology, 2:27:1--27:27, 2011.
  209. <a href="http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf">pdf</a>, <a href=http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.ps.gz>ps.gz</a>,
  210. <a href=http://portal.acm.org/citation.cfm?id=1961199&CFID=29950432&CFTOKEN=30974232>ACM digital lib</a>.
  211. <li> Instructions for using LIBSVM are in the README files in the main directory and some sub-directories.
  212. <br>
  213. README in the main directory: details all options, data format, and library calls.
  214. <br>
  215. tools/README: parameter selection and other tools
  216. <li>
  217. A guide for beginners:
  218. <br>
  219. C.-W. Hsu, C.-C. Chang, and
  220. C.-J. Lin.
  221. <A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf">
  222. A practical guide to support vector classification
  223. </A>
  224. <li> An <a href=http://www.youtube.com/watch?v=gePWtNAQcK8>introductory video</a>
  225. for windows users.
  226. </ul>
  227. <p align="right">
  228. <a href="#_TOP">[Go Top]</a>
  229. <hr/>
  230. <a name="/Q02:_Installation_and_running_the_program"></a>
  231. <a name="f202"><b>Q: Where are change log and earlier versions?</b></a>
  232. <br/>
  233. <p>See <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/log">the change log</a>.
  234. <p> You can download earlier versions
  235. <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/oldfiles">here</a>.
  236. <p align="right">
  237. <a href="#_TOP">[Go Top]</a>
  238. <hr/>
  239. <a name="/Q02:_Installation_and_running_the_program"></a>
  240. <a name="f203"><b>Q: How to cite LIBSVM?</b></a>
  241. <br/>
  242. <p>
  243. Please cite the following paper:
  244. <p>
  245. Chih-Chung Chang and Chih-Jen Lin, LIBSVM
  246. : a library for support vector machines.
  247. ACM Transactions on Intelligent Systems and Technology, 2:27:1--27:27, 2011.
  248. Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm
  249. <p>
  250. The bibtex format is
  251. <pre>
  252. @article{CC01a,
  253. author = {Chang, Chih-Chung and Lin, Chih-Jen},
  254. title = {{LIBSVM}: A library for support vector machines},
  255. journal = {ACM Transactions on Intelligent Systems and Technology},
  256. volume = {2},
  257. issue = {3},
  258. year = {2011},
  259. pages = {27:1--27:27},
  260. note = {Software available at \url{http://www.csie.ntu.edu.tw/~cjlin/libsvm}}
  261. }
  262. </pre>
  263. <p align="right">
  264. <a href="#_TOP">[Go Top]</a>
  265. <hr/>
  266. <a name="/Q02:_Installation_and_running_the_program"></a>
  267. <a name="f204"><b>Q: I would like to use libsvm in my software. Is there any license problem?</b></a>
  268. <br/>
  269. <p>
  270. We have "the modified BSD license,"
  271. so it is very easy to
  272. use libsvm in your software.
  273. Please check the COPYRIGHT file in detail. Basically
  274. you need to
  275. <ol>
  276. <li>
  277. Clearly indicate that LIBSVM is used.
  278. </li>
  279. <li>
  280. Retain the LIBSVM COPYRIGHT file in your software.
  281. </li>
  282. </ol>
  283. It can also be used in commercial products.
  284. <p align="right">
  285. <a href="#_TOP">[Go Top]</a>
  286. <hr/>
  287. <a name="/Q02:_Installation_and_running_the_program"></a>
  288. <a name="f205"><b>Q: Is there a repository of additional tools based on libsvm?</b></a>
  289. <br/>
  290. <p>
  291. Yes, see <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvmtools">libsvm
  292. tools</a>
  293. <p align="right">
  294. <a href="#_TOP">[Go Top]</a>
  295. <hr/>
  296. <a name="/Q02:_Installation_and_running_the_program"></a>
  297. <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>
  298. <br/>
  299. <p>
  300. This usually happens if you compile the code
  301. on one machine and run it on another which has incompatible
  302. libraries.
  303. Try to recompile the program on that machine or use static linking.
  304. <p align="right">
  305. <a href="#_TOP">[Go Top]</a>
  306. <hr/>
  307. <a name="/Q02:_Installation_and_running_the_program"></a>
  308. <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>
  309. <br/>
  310. <p>
  311. Build it as a project by choosing "Win32 Project."
  312. On the other hand, for "svm-train" and "svm-predict"
  313. you want to choose "Win32 Console Project."
  314. After libsvm 2.5, you can also use the file Makefile.win.
  315. See details in README.
  316. <p>
  317. If you are not using Makefile.win and see the following
  318. link error
  319. <pre>
  320. LIBCMTD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol
  321. _wWinMain@16
  322. </pre>
  323. you may have selected a wrong project type.
  324. <p align="right">
  325. <a href="#_TOP">[Go Top]</a>
  326. <hr/>
  327. <a name="/Q02:_Installation_and_running_the_program"></a>
  328. <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>
  329. <br/>
  330. <p>
  331. You need to open a command window
  332. and type svmtrain.exe to see all options.
  333. Some examples are in README file.
  334. <p align="right">
  335. <a href="#_TOP">[Go Top]</a>
  336. <hr/>
  337. <a name="/Q02:_Installation_and_running_the_program"></a>
  338. <a name="f209"><b>Q: What is the difference between "." and "*" outputed during training? </b></a>
  339. <br/>
  340. <p>
  341. "." means every 1,000 iterations (or every #data
  342. iterations is your #data is less than 1,000).
  343. "*" means that after iterations of using
  344. a smaller shrunk problem,
  345. we reset to use the whole set. See the
  346. <a href=../papers/libsvm.pdf>implementation document</a> for details.
  347. <p align="right">
  348. <a href="#_TOP">[Go Top]</a>
  349. <hr/>
  350. <a name="/Q02:_Installation_and_running_the_program"></a>
  351. <a name="f210"><b>Q: Why occasionally the program (including MATLAB or other interfaces) crashes and gives a segmentation fault?</b></a>
  352. <br/>
  353. <p>
  354. Very likely the program consumes too much memory than what the
  355. operating system can provide. Try a smaller data and see if the
  356. program still crashes.
  357. <p align="right">
  358. <a href="#_TOP">[Go Top]</a>
  359. <hr/>
  360. <a name="/Q02:_Installation_and_running_the_program"></a>
  361. <a name="f211"><b>Q: How to build a dynamic library (.dll file) on MS windows?</b></a>
  362. <br/>
  363. <p>
  364. The easiest way is to use Makefile.win.
  365. See details in README.
  366. Alternatively, you can use Visual C++. Here is
  367. the example using Visual Studio 2013:
  368. <ol>
  369. <li>Create a Win32 empty DLL project and set (in Project->$Project_Name
  370. Properties...->Configuration) to "Release."
  371. About how to create a new dynamic link library, please refer to
  372. <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>
  373. <li> Add svm.cpp, svm.h to your project.
  374. <li> Add __WIN32__ and _CRT_SECURE_NO_DEPRECATE to Preprocessor definitions (in
  375. Project->$Project_Name Properties...->C/C++->Preprocessor)
  376. <li> Set Create/Use Precompiled Header to Not Using Precompiled Headers
  377. (in Project->$Project_Name Properties...->C/C++->Precompiled Headers)
  378. <li> Set the path for the Modulation Definition File svm.def (in
  379. Project->$Project_Name Properties...->Linker->input
  380. <li> Build the DLL.
  381. <li> Rename the dll file to libsvm.dll and move it to the correct path.
  382. </ol>
  383. <p align="right">
  384. <a href="#_TOP">[Go Top]</a>
  385. <hr/>
  386. <a name="/Q02:_Installation_and_running_the_program"></a>
  387. <a name="f212"><b>Q: On some systems (e.g., Ubuntu), compiling LIBSVM gives many warning messages. Is this a problem and how to disable the warning message?</b></a>
  388. <br/>
  389. <p>
  390. If you are using a version before 3.18, probably you see
  391. a warning message like
  392. <pre>
  393. svm.cpp:2730: warning: ignoring return value of int fscanf(FILE*, const char*, ...), declared with attribute warn_unused_result
  394. </pre>
  395. This is not a problem; see <a href=https://wiki.ubuntu.com/CompilerFlags#-D_FORTIFY_SOURCE=2>this page</a> for more
  396. details of ubuntu systems.
  397. To disable the warning message you can replace
  398. <pre>
  399. CFLAGS = -Wall -Wconversion -O3 -fPIC
  400. </pre>
  401. with
  402. <pre>
  403. CFLAGS = -Wall -Wconversion -O3 -fPIC -U_FORTIFY_SOURCE
  404. </pre>
  405. in Makefile.
  406. <p> After version 3.18, we have a better setting so that such warning messages do not appear.
  407. <p align="right">
  408. <a href="#_TOP">[Go Top]</a>
  409. <hr/>
  410. <a name="/Q02:_Installation_and_running_the_program"></a>
  411. <a name="f213"><b>Q: In LIBSVM, why you don't use certain C/C++ library functions to make the code shorter?</b></a>
  412. <br/>
  413. <p>
  414. For portability, we use only features defined in ISO C89. Note that features in ISO C99 may not be available everywhere.
  415. Even the newest gcc lacks some features in C99 (see <a href=http://gcc.gnu.org/c99status.html>http://gcc.gnu.org/c99status.html</a> for details).
  416. If the situation changes in the future,
  417. we might consider using these newer features.
  418. <p align="right">
  419. <a href="#_TOP">[Go Top]</a>
  420. <hr/>
  421. <a name="/Q03:_Data_preparation"></a>
  422. <a name="f301"><b>Q: Why sometimes not all attributes of a data appear in the training/model files ?</b></a>
  423. <br/>
  424. <p>
  425. libsvm uses the so called "sparse" format where zero
  426. values do not need to be stored. Hence a data with attributes
  427. <pre>
  428. 1 0 2 0
  429. </pre>
  430. is represented as
  431. <pre>
  432. 1:1 3:2
  433. </pre>
  434. <p align="right">
  435. <a href="#_TOP">[Go Top]</a>
  436. <hr/>
  437. <a name="/Q03:_Data_preparation"></a>
  438. <a name="f302"><b>Q: What if my data are non-numerical ?</b></a>
  439. <br/>
  440. <p>
  441. Currently libsvm supports only numerical data.
  442. You may have to change non-numerical data to
  443. numerical. For example, you can use several
  444. binary attributes to represent a categorical
  445. attribute.
  446. <p align="right">
  447. <a href="#_TOP">[Go Top]</a>
  448. <hr/>
  449. <a name="/Q03:_Data_preparation"></a>
  450. <a name="f303"><b>Q: Why do you consider sparse format ? Will the training of dense data be much slower ?</b></a>
  451. <br/>
  452. <p>
  453. This is a controversial issue. The kernel
  454. evaluation (i.e. inner product) of sparse vectors is slower
  455. so the total training time can be at least twice or three times
  456. of that using the dense format.
  457. However, we cannot support only dense format as then we CANNOT
  458. handle extremely sparse cases. Simplicity of the code is another
  459. concern. Right now we decide to support
  460. the sparse format only.
  461. <p align="right">
  462. <a href="#_TOP">[Go Top]</a>
  463. <hr/>
  464. <a name="/Q03:_Data_preparation"></a>
  465. <a name="f304"><b>Q: Why sometimes the last line of my data is not read by svm-train?</b></a>
  466. <br/>
  467. <p>
  468. We assume that you have '\n' in the end of
  469. each line. So please press enter in the end
  470. of your last line.
  471. <p align="right">
  472. <a href="#_TOP">[Go Top]</a>
  473. <hr/>
  474. <a name="/Q03:_Data_preparation"></a>
  475. <a name="f305"><b>Q: Is there a program to check if my data are in the correct format?</b></a>
  476. <br/>
  477. <p>
  478. The svm-train program in libsvm conducts only a simple check of the input data. To do a
  479. detailed check, after libsvm 2.85, you can use the python script tools/checkdata.py. See tools/README for details.
  480. <p align="right">
  481. <a href="#_TOP">[Go Top]</a>
  482. <hr/>
  483. <a name="/Q03:_Data_preparation"></a>
  484. <a name="f306"><b>Q: May I put comments in data files?</b></a>
  485. <br/>
  486. <p>
  487. We don't officially support this. But, currently LIBSVM
  488. is able to process data in the following
  489. format:
  490. <pre>
  491. 1 1:2 2:1 # your comments
  492. </pre>
  493. Note that the character ":" should not appear in your
  494. comments.
  495. <!--
  496. No, for simplicity we don't support that.
  497. However, you can easily preprocess your data before
  498. using libsvm. For example,
  499. if you have the following data
  500. <pre>
  501. test.txt
  502. 1 1:2 2:1 # proten A
  503. </pre>
  504. then on unix machines you can do
  505. <pre>
  506. cut -d '#' -f 1 < test.txt > test.features
  507. cut -d '#' -f 2 < test.txt > test.comments
  508. svm-predict test.feature train.model test.predicts
  509. paste -d '#' test.predicts test.comments | sed 's/#/ #/' > test.results
  510. </pre>
  511. -->
  512. <p align="right">
  513. <a href="#_TOP">[Go Top]</a>
  514. <hr/>
  515. <a name="/Q03:_Data_preparation"></a>
  516. <a name="f307"><b>Q: How to convert other data formats to LIBSVM format?</b></a>
  517. <br/>
  518. <p>
  519. It depends on your data format. A simple way is to use
  520. libsvmwrite in the libsvm matlab/octave interface.
  521. Take a CSV (comma-separated values) file
  522. in UCI machine learning repository as an example.
  523. We download <a href=http://archive.ics.uci.edu/ml/machine-learning-databases/spect/SPECTF.train>SPECTF.train</a>.
  524. Labels are in the first column. The following steps produce
  525. a file in the libsvm format.
  526. <pre>
  527. matlab> SPECTF = csvread('SPECTF.train'); % read a csv file
  528. matlab> labels = SPECTF(:, 1); % labels from the 1st column
  529. matlab> features = SPECTF(:, 2:end);
  530. matlab> features_sparse = sparse(features); % features must be in a sparse matrix
  531. matlab> libsvmwrite('SPECTFlibsvm.train', labels, features_sparse);
  532. </pre>
  533. The tranformed data are stored in SPECTFlibsvm.train.
  534. <p>
  535. Alternatively, you can use <a href="./faqfiles/convert.c">convert.c</a>
  536. to convert CSV format to libsvm format.
  537. <p align="right">
  538. <a href="#_TOP">[Go Top]</a>
  539. <hr/>
  540. <a name="/Q04:_Training_and_prediction"></a>
  541. <a name="f401"><b>Q: The output of training C-SVM is like the following. What do they mean?</b></a>
  542. <br/>
  543. <br>optimization finished, #iter = 219
  544. <br>nu = 0.431030
  545. <br>obj = -100.877286, rho = 0.424632
  546. <br>nSV = 132, nBSV = 107
  547. <br>Total nSV = 132
  548. <p>
  549. obj is the optimal objective value of the dual SVM problem.
  550. rho is the bias term in the decision function
  551. sgn(w^Tx - rho).
  552. nSV and nBSV are number of support vectors and bounded support
  553. vectors (i.e., alpha_i = C). nu-svm is a somewhat equivalent
  554. form of C-SVM where C is replaced by nu. nu simply shows the
  555. corresponding parameter. More details are in
  556. <a href="http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf">
  557. libsvm document</a>.
  558. <p align="right">
  559. <a href="#_TOP">[Go Top]</a>
  560. <hr/>
  561. <a name="/Q04:_Training_and_prediction"></a>
  562. <a name="f402"><b>Q: Can you explain more about the model file?</b></a>
  563. <br/>
  564. <p>
  565. In the model file, after parameters and other informations such as labels , each line represents a support vector.
  566. Support vectors are listed in the order of "labels" shown earlier.
  567. (i.e., those from the first class in the "labels" list are
  568. grouped first, and so on.)
  569. If k is the total number of classes,
  570. in front of a support vector in class j, there are
  571. k-1 coefficients
  572. y*alpha where alpha are dual solution of the
  573. following two class problems:
  574. <br>
  575. 1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k
  576. <br>
  577. and y=1 in first j-1 coefficients, y=-1 in the remaining
  578. k-j coefficients.
  579. For example, if there are 4 classes, the file looks like:
  580. <pre>
  581. +-+-+-+--------------------+
  582. |1|1|1| |
  583. |v|v|v| SVs from class 1 |
  584. |2|3|4| |
  585. +-+-+-+--------------------+
  586. |1|2|2| |
  587. |v|v|v| SVs from class 2 |
  588. |2|3|4| |
  589. +-+-+-+--------------------+
  590. |1|2|3| |
  591. |v|v|v| SVs from class 3 |
  592. |3|3|4| |
  593. +-+-+-+--------------------+
  594. |1|2|3| |
  595. |v|v|v| SVs from class 4 |
  596. |4|4|4| |
  597. +-+-+-+--------------------+
  598. </pre>
  599. See also
  600. <a href="#f804"> an illustration using
  601. MATLAB/OCTAVE.</a>
  602. <p align="right">
  603. <a href="#_TOP">[Go Top]</a>
  604. <hr/>
  605. <a name="/Q04:_Training_and_prediction"></a>
  606. <a name="f403"><b>Q: Should I use float or double to store numbers in the cache ?</b></a>
  607. <br/>
  608. <p>
  609. We have float as the default as you can store more numbers
  610. in the cache.
  611. In general this is good enough but for few difficult
  612. cases (e.g. C very very large) where solutions are huge
  613. numbers, it might be possible that the numerical precision is not
  614. enough using only float.
  615. <p align="right">
  616. <a href="#_TOP">[Go Top]</a>
  617. <hr/>
  618. <a name="/Q04:_Training_and_prediction"></a>
  619. <a name="f405"><b>Q: Does libsvm have special treatments for linear SVM?</b></a>
  620. <br/>
  621. <p>
  622. No, libsvm solves linear/nonlinear SVMs by the
  623. same way.
  624. Some tricks may save training/testing time if the
  625. linear kernel is used,
  626. so libsvm is <b>NOT</b> particularly efficient for linear SVM,
  627. especially when
  628. C is large and
  629. the number of data is much larger
  630. than the number of attributes.
  631. You can either
  632. <ul>
  633. <li>
  634. Use small C only. We have shown in the following paper
  635. that after C is larger than a certain threshold,
  636. the decision function is the same.
  637. <p>
  638. <a href="http://guppy.mpe.nus.edu.sg/~mpessk/">S. S. Keerthi</a>
  639. and
  640. <B>C.-J. Lin</B>.
  641. <A HREF="papers/limit.pdf">
  642. Asymptotic behaviors of support vector machines with
  643. Gaussian kernel
  644. </A>
  645. .
  646. <I><A HREF="http://mitpress.mit.edu/journal-home.tcl?issn=08997667">Neural Computation</A></I>, 15(2003), 1667-1689.
  647. <li>
  648. Check <a href=http://www.csie.ntu.edu.tw/~cjlin/liblinear>liblinear</a>,
  649. which is designed for large-scale linear classification.
  650. </ul>
  651. <p> Please also see our <a href=../papers/guide/guide.pdf>SVM guide</a>
  652. on the discussion of using RBF and linear
  653. kernels.
  654. <p align="right">
  655. <a href="#_TOP">[Go Top]</a>
  656. <hr/>
  657. <a name="/Q04:_Training_and_prediction"></a>
  658. <a name="f406"><b>Q: The number of free support vectors is large. What should I do?</b></a>
  659. <br/>
  660. <p>
  661. This usually happens when the data are overfitted.
  662. If attributes of your data are in large ranges,
  663. try to scale them. Then the region
  664. of appropriate parameters may be larger.
  665. Note that there is a scale program
  666. in libsvm.
  667. <p align="right">
  668. <a href="#_TOP">[Go Top]</a>
  669. <hr/>
  670. <a name="/Q04:_Training_and_prediction"></a>
  671. <a name="f407"><b>Q: Should I scale training and testing data in a similar way?</b></a>
  672. <br/>
  673. <p>
  674. Yes, you can do the following:
  675. <pre>
  676. > svm-scale -s scaling_parameters train_data > scaled_train_data
  677. > svm-scale -r scaling_parameters test_data > scaled_test_data
  678. </pre>
  679. <p align="right">
  680. <a href="#_TOP">[Go Top]</a>
  681. <hr/>
  682. <a name="/Q04:_Training_and_prediction"></a>
  683. <a name="f4071"><b>Q: On windows sometimes svm-scale.exe generates some non-ASCII data not good for training/prediction?</b></a>
  684. <br/>
  685. <p>
  686. In general this does not happen, but we have observed in some rare
  687. situations, the output of svm-scale.exe directed to a file (by ">")
  688. has wrong encoding. That is, the file is not an ASCII file, so cannot be
  689. used for training/prediction. Please let us know if this happens as at this moment
  690. we don't clearly see how to fix the problem.
  691. <p align="right">
  692. <a href="#_TOP">[Go Top]</a>
  693. <hr/>
  694. <a name="/Q04:_Training_and_prediction"></a>
  695. <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>
  696. <br/>
  697. <p>
  698. For the linear scaling method, if the RBF kernel is
  699. used and parameter selection is conducted, there
  700. is no difference. Assume Mi and mi are
  701. respectively the maximal and minimal values of the
  702. ith attribute. Scaling to [0,1] means
  703. <pre>
  704. x'=(x-mi)/(Mi-mi)
  705. </pre>
  706. For [-1,1],
  707. <pre>
  708. x''=2(x-mi)/(Mi-mi)-1.
  709. </pre>
  710. In the RBF kernel,
  711. <pre>
  712. x'-y'=(x-y)/(Mi-mi), x''-y''=2(x-y)/(Mi-mi).
  713. </pre>
  714. Hence, using (C,g) on the [0,1]-scaled data is the
  715. same as (C,g/2) on the [-1,1]-scaled data.
  716. <p> Though the performance is the same, the computational
  717. time may be different. For data with many zero entries,
  718. [0,1]-scaling keeps the sparsity of input data and hence
  719. may save the time.
  720. <p align="right">
  721. <a href="#_TOP">[Go Top]</a>
  722. <hr/>
  723. <a name="/Q04:_Training_and_prediction"></a>
  724. <a name="f409"><b>Q: The prediction rate is low. How could I improve it?</b></a>
  725. <br/>
  726. <p>
  727. Try to use the model selection tool grid.py in the tools
  728. directory find
  729. out good parameters. To see the importance of model selection,
  730. please
  731. see our guide for beginners:
  732. <A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf">
  733. A practical guide to support vector
  734. classification
  735. </A>
  736. <p align="right">
  737. <a href="#_TOP">[Go Top]</a>
  738. <hr/>
  739. <a name="/Q04:_Training_and_prediction"></a>
  740. <a name="f410"><b>Q: My data are unbalanced. Could libsvm handle such problems?</b></a>
  741. <br/>
  742. <p>
  743. Yes, there is a -wi options. For example, if you use
  744. <pre>
  745. > svm-train -s 0 -c 10 -w1 1 -w-1 5 data_file
  746. </pre>
  747. <p>
  748. the penalty for class "-1" is larger.
  749. Note that this -w option is for C-SVC only.
  750. <p align="right">
  751. <a href="#_TOP">[Go Top]</a>
  752. <hr/>
  753. <a name="/Q04:_Training_and_prediction"></a>
  754. <a name="f411"><b>Q: What is the difference between nu-SVC and C-SVC?</b></a>
  755. <br/>
  756. <p>
  757. Basically they are the same thing but with different
  758. parameters. The range of C is from zero to infinity
  759. but nu is always between [0,1]. A nice property
  760. of nu is that it is related to the ratio of
  761. support vectors and the ratio of the training
  762. error.
  763. <p align="right">
  764. <a href="#_TOP">[Go Top]</a>
  765. <hr/>
  766. <a name="/Q04:_Training_and_prediction"></a>
  767. <a name="f412"><b>Q: The program keeps running (without showing any output). What should I do?</b></a>
  768. <br/>
  769. <p>
  770. You may want to check your data. Each training/testing
  771. data must be in one line. It cannot be separated.
  772. In addition, you have to remove empty lines.
  773. <p align="right">
  774. <a href="#_TOP">[Go Top]</a>
  775. <hr/>
  776. <a name="/Q04:_Training_and_prediction"></a>
  777. <a name="f413"><b>Q: The program keeps running (with output, i.e. many dots). What should I do?</b></a>
  778. <br/>
  779. <p>
  780. In theory libsvm guarantees to converge.
  781. Therefore, this means you are
  782. handling ill-conditioned situations
  783. (e.g. too large/small parameters) so numerical
  784. difficulties occur.
  785. <p>
  786. You may get better numerical stability by replacing
  787. <pre>
  788. typedef float Qfloat;
  789. </pre>
  790. in svm.cpp with
  791. <pre>
  792. typedef double Qfloat;
  793. </pre>
  794. That is, elements in the kernel cache are stored
  795. in double instead of single. However, this means fewer elements
  796. can be put in the kernel cache.
  797. <p align="right">
  798. <a href="#_TOP">[Go Top]</a>
  799. <hr/>
  800. <a name="/Q04:_Training_and_prediction"></a>
  801. <a name="f414"><b>Q: The training time is too long. What should I do?</b></a>
  802. <br/>
  803. <p>
  804. For large problems, please specify enough cache size (i.e.,
  805. -m).
  806. Slow convergence may happen for some difficult cases (e.g. -c is large).
  807. You can try to use a looser stopping tolerance with -e.
  808. If that still doesn't work, you may train only a subset of the data.
  809. You can use the program subset.py in the directory "tools"
  810. to obtain a random subset.
  811. <p>
  812. If you have extremely large data and face this difficulty, please
  813. contact us. We will be happy to discuss possible solutions.
  814. <p> When using large -e, you may want to check if -h 0 (no shrinking) or -h 1 (shrinking) is faster.
  815. See a related question below.
  816. <p align="right">
  817. <a href="#_TOP">[Go Top]</a>
  818. <hr/>
  819. <a name="/Q04:_Training_and_prediction"></a>
  820. <a name="f4141"><b>Q: Does shrinking always help?</b></a>
  821. <br/>
  822. <p>
  823. If the number of iterations is high, then shrinking
  824. often helps.
  825. However, if the number of iterations is small
  826. (e.g., you specify a large -e), then
  827. probably using -h 0 (no shrinking) is better.
  828. See the
  829. <a href=../papers/libsvm.pdf>implementation document</a> for details.
  830. <p align="right">
  831. <a href="#_TOP">[Go Top]</a>
  832. <hr/>
  833. <a name="/Q04:_Training_and_prediction"></a>
  834. <a name="f415"><b>Q: How do I get the decision value(s)?</b></a>
  835. <br/>
  836. <p>
  837. We print out decision values for regression. For classification,
  838. we solve several binary SVMs for multi-class cases. You
  839. can obtain values by easily calling the subroutine
  840. svm_predict_values. Their corresponding labels
  841. can be obtained from svm_get_labels.
  842. Details are in
  843. README of libsvm package.
  844. <p>
  845. If you are using MATLAB/OCTAVE interface, svmpredict can directly
  846. give you decision values. Please see matlab/README for details.
  847. <p>
  848. We do not recommend the following. But if you would
  849. like to get values for
  850. TWO-class classification with labels +1 and -1
  851. (note: +1 and -1 but not things like 5 and 10)
  852. in the easiest way, simply add
  853. <pre>
  854. printf("%f\n", dec_values[0]*model->label[0]);
  855. </pre>
  856. after the line
  857. <pre>
  858. svm_predict_values(model, x, dec_values);
  859. </pre>
  860. of the file svm.cpp.
  861. Positive (negative)
  862. decision values correspond to data predicted as +1 (-1).
  863. <p align="right">
  864. <a href="#_TOP">[Go Top]</a>
  865. <hr/>
  866. <a name="/Q04:_Training_and_prediction"></a>
  867. <a name="f4151"><b>Q: How do I get the distance between a point and the hyperplane?</b></a>
  868. <br/>
  869. <p>
  870. The distance is |decision_value| / |w|.
  871. We have |w|^2 = w^Tw = alpha^T Q alpha = 2*(dual_obj + sum alpha_i).
  872. Thus in svm.cpp please find the place
  873. where we calculate the dual objective value
  874. (i.e., the subroutine Solve())
  875. and add a statement to print w^Tw.
  876. More precisely, here is what you need to do
  877. <ol>
  878. <li>Search for "calculate objective value" in svm.cpp
  879. </li>
  880. <li> In that place, si->obj is the variable for the objective value
  881. </li>
  882. <li> Add a for loop to calculate the sum of alpha
  883. </li>
  884. <li> Calculate 2*(si->obj + sum of alpha) and print the square root of it. You now get |w|. You
  885. need to recompile the code
  886. </li>
  887. <li> Check an earlier FAQ on printing decision values. You
  888. need to recompile the code
  889. </li>
  890. <li>
  891. Then print decision value divided by the |w| value obtained earlier.
  892. </li>
  893. </ol>
  894. <p align="right">
  895. <a href="#_TOP">[Go Top]</a>
  896. <hr/>
  897. <a name="/Q04:_Training_and_prediction"></a>
  898. <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>
  899. <br/>
  900. <p>
  901. On 32-bit machines, the maximum addressable
  902. memory is 4GB. The Linux kernel uses 3:1
  903. split which means user space is 3G and
  904. kernel space is 1G. Although there are
  905. 3G user space, the maximum dynamic allocation
  906. memory is 2G. So, if you specify -m near 2G,
  907. the memory will be exhausted. And svm-train
  908. will fail when it asks more memory.
  909. For more details, please read
  910. <a href=http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3BA164F6.BAFA4FB%40daimi.au.dk>
  911. this article</a>.
  912. <p>
  913. The easiest solution is to switch to a
  914. 64-bit machine.
  915. Otherwise, there are two ways to solve this. If your
  916. machine supports Intel's PAE (Physical Address
  917. Extension), you can turn on the option HIGHMEM64G
  918. in Linux kernel which uses 4G:4G split for
  919. kernel and user space. If you don't, you can
  920. try a software `tub' which can eliminate the 2G
  921. boundary for dynamic allocated memory. The `tub'
  922. is available at
  923. <a href=http://www.bitwagon.com/tub.html>http://www.bitwagon.com/tub.html</a>.
  924. <!--
  925. This may happen only when the cache is large, but each cached row is
  926. not large enough. <b>Note:</b> This problem is specific to
  927. gnu C library which is used in linux.
  928. The solution is as follows:
  929. <p>
  930. In our program we have malloc() which uses two methods
  931. to allocate memory from kernel. One is
  932. sbrk() and another is mmap(). sbrk is faster, but mmap
  933. has a larger address
  934. space. So malloc uses mmap only if the wanted memory size is larger
  935. than some threshold (default 128k).
  936. In the case where each row is not large enough (#elements < 128k/sizeof(float)) but we need a large cache ,
  937. the address space for sbrk can be exhausted. The solution is to
  938. lower the threshold to force malloc to use mmap
  939. and increase the maximum number of chunks to allocate
  940. with mmap.
  941. <p>
  942. Therefore, in the main program (i.e. svm-train.c) you want
  943. to have
  944. <pre>
  945. #include &lt;malloc.h&gt;
  946. </pre>
  947. and then in main():
  948. <pre>
  949. mallopt(M_MMAP_THRESHOLD, 32768);
  950. mallopt(M_MMAP_MAX,1000000);
  951. </pre>
  952. You can also set the environment variables instead
  953. of writing them in the program:
  954. <pre>
  955. $ M_MMAP_MAX=1000000 M_MMAP_THRESHOLD=32768 ./svm-train .....
  956. </pre>
  957. More information can be found by
  958. <pre>
  959. $ info libc "Malloc Tunable Parameters"
  960. </pre>
  961. -->
  962. <p align="right">
  963. <a href="#_TOP">[Go Top]</a>
  964. <hr/>
  965. <a name="/Q04:_Training_and_prediction"></a>
  966. <a name="f417"><b>Q: How do I disable screen output of svm-train?</b></a>
  967. <br/>
  968. <p>
  969. For commend-line users, use the -q option:
  970. <pre>
  971. > ./svm-train -q heart_scale
  972. </pre>
  973. <p>
  974. For library users, set the global variable
  975. <pre>
  976. extern void (*svm_print_string) (const char *);
  977. </pre>
  978. to specify the output format. You can disable the output by the following steps:
  979. <ol>
  980. <li>
  981. Declare a function to output nothing:
  982. <pre>
  983. void print_null(const char *s) {}
  984. </pre>
  985. </li>
  986. <li>
  987. Assign the output function of libsvm by
  988. <pre>
  989. svm_print_string = &print_null;
  990. </pre>
  991. </li>
  992. </ol>
  993. Finally, a way used in earlier libsvm
  994. is by updating svm.cpp from
  995. <pre>
  996. #if 1
  997. void info(const char *fmt,...)
  998. </pre>
  999. to
  1000. <pre>
  1001. #if 0
  1002. void info(const char *fmt,...)
  1003. </pre>
  1004. <p align="right">
  1005. <a href="#_TOP">[Go Top]</a>
  1006. <hr/>
  1007. <a name="/Q04:_Training_and_prediction"></a>
  1008. <a name="f418"><b>Q: I would like to use my own kernel. Any example? In svm.cpp, there are two subroutines for kernel evaluations: k_function() and kernel_function(). Which one should I modify ?</b></a>
  1009. <br/>
  1010. <p>
  1011. An example is "LIBSVM for string data" in LIBSVM Tools.
  1012. <p>
  1013. The reason why we have two functions is as follows.
  1014. For the RBF kernel exp(-g |xi - xj|^2), if we calculate
  1015. xi - xj first and then the norm square, there are 3n operations.
  1016. Thus we consider exp(-g (|xi|^2 - 2dot(xi,xj) +|xj|^2))
  1017. and by calculating all |xi|^2 in the beginning,
  1018. the number of operations is reduced to 2n.
  1019. This is for the training. For prediction we cannot
  1020. do this so a regular subroutine using that 3n operations is
  1021. needed.
  1022. The easiest way to have your own kernel is
  1023. to put the same code in these two
  1024. subroutines by replacing any kernel.
  1025. <p align="right">
  1026. <a href="#_TOP">[Go Top]</a>
  1027. <hr/>
  1028. <a name="/Q04:_Training_and_prediction"></a>
  1029. <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>
  1030. <br/>
  1031. <p>
  1032. It is one-against-one. We chose it after doing the following
  1033. comparison:
  1034. C.-W. Hsu and C.-J. Lin.
  1035. <A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/multisvm.pdf">
  1036. A comparison of methods
  1037. for multi-class support vector machines
  1038. </A>,
  1039. <I>IEEE Transactions on Neural Networks</A></I>, 13(2002), 415-425.
  1040. <p>
  1041. "1-against-the rest" is a good method whose performance
  1042. is comparable to "1-against-1." We do the latter
  1043. simply because its training time is shorter.
  1044. <p align="right">
  1045. <a href="#_TOP">[Go Top]</a>
  1046. <hr/>
  1047. <a name="/Q04:_Training_and_prediction"></a>
  1048. <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>
  1049. <br/>
  1050. <p>
  1051. It is extremely easy. Taking c-svc for example, to solve
  1052. <p>
  1053. min_w w^Tw/2 + C \sum max(0, 1- (y_i w^Tx_i+b))^2,
  1054. <p>
  1055. only two
  1056. places of svm.cpp have to be changed.
  1057. First, modify the following line of
  1058. solve_c_svc from
  1059. <pre>
  1060. s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
  1061. alpha, Cp, Cn, param->eps, si, param->shrinking);
  1062. </pre>
  1063. to
  1064. <pre>
  1065. s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
  1066. alpha, INF, INF, param->eps, si, param->shrinking);
  1067. </pre>
  1068. Second, in the class of SVC_Q, declare C as
  1069. a private variable:
  1070. <pre>
  1071. double C;
  1072. </pre>
  1073. In the constructor replace
  1074. <pre>
  1075. for(int i=0;i&lt;prob.l;i++)
  1076. QD[i]= (Qfloat)(this->*kernel_function)(i,i);
  1077. </pre>
  1078. with
  1079. <pre>
  1080. this->C = param.C;
  1081. for(int i=0;i&lt;prob.l;i++)
  1082. QD[i]= (Qfloat)(this->*kernel_function)(i,i)+0.5/C;
  1083. </pre>
  1084. Then in the subroutine get_Q, after the for loop, add
  1085. <pre>
  1086. if(i >= start && i < len)
  1087. data[i] += 0.5/C;
  1088. </pre>
  1089. <p>
  1090. 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:
  1091. <pre>
  1092. data[real_i] += 0.5/C;
  1093. </pre>
  1094. <p>
  1095. For large linear L2-loss SVM, please use
  1096. <a href=../liblinear>LIBLINEAR</a>.
  1097. <p align="right">
  1098. <a href="#_TOP">[Go Top]</a>
  1099. <hr/>
  1100. <a name="/Q04:_Training_and_prediction"></a>
  1101. <a name="f425"><b>Q: In one-class SVM, parameter nu should be an upper bound of the training error rate. Why sometimes I get a training error rate bigger than nu?</b></a>
  1102. <br/>
  1103. <p>
  1104. At optimum, some training instances should satisfy
  1105. w^Tx - rho = 0. However, numerically they may be slightly
  1106. smaller than zero
  1107. Then they are wrongly counted
  1108. as training errors. You can use a smaller stopping tolerance
  1109. (by the -e option) to make this problem less serious.
  1110. <p>
  1111. This issue <b>does not occur</b> for nu-SVC for
  1112. two-class classification.
  1113. We have that
  1114. <ol>
  1115. <li>nu is an upper bound on the ratio of training points
  1116. on the wrong side of the hyperplane, and
  1117. <li>therefore, nu is also an upper bound on the training error rate.
  1118. </ol>
  1119. Numerical issues occur in calculating the first case
  1120. because some training points satisfying y(w^Tx + b) - rho = 0
  1121. become negative.
  1122. However, we have no numerical problems for the second case because
  1123. we compare y(w^Tx + b) and 0 for counting training errors.
  1124. <p align="right">
  1125. <a href="#_TOP">[Go Top]</a>
  1126. <hr/>
  1127. <a name="/Q04:_Training_and_prediction"></a>
  1128. <a name="f427"><b>Q: Why the code gives NaN (not a number) results?</b></a>
  1129. <br/>
  1130. <p>
  1131. This rarely happens, but few users reported the problem.
  1132. It seems that their
  1133. computers for training libsvm have the VPN client
  1134. running. The VPN software has some bugs and causes this
  1135. problem. Please try to close or disconnect the VPN client.
  1136. <p align="right">
  1137. <a href="#_TOP">[Go Top]</a>
  1138. <hr/>
  1139. <a name="/Q04:_Training_and_prediction"></a>
  1140. <a name="f430"><b>Q: Why the sign of predicted labels and decision values are sometimes reversed?</b></a>
  1141. <br/>
  1142. <p>
  1143. This situation may occur <b>before version 3.17</b>.
  1144. Nothing is wrong. Very likely you have two labels +1/-1 and the first instance in your data
  1145. has -1. We give the following explanation.
  1146. <p>
  1147. Internally class labels are ordered by their first occurrence in the training set. For a k-class data, internally labels
  1148. are 0, ..., k-1, and each two-class SVM considers pair
  1149. (i, j) with i < j. Then class i is treated as positive (+1)
  1150. and j as negative (-1).
  1151. For example, if the data set has labels +5/+10 and +10 appears
  1152. first, then internally the +5 versus +10 SVM problem
  1153. has +10 as positive (+1) and +5 as negative (-1).
  1154. <p>
  1155. By this setting, if you have labels +1 and -1,
  1156. it's possible that internally they correspond to -1 and +1,
  1157. respectively. Some new users have been confused about
  1158. this, so <b>after version 3.17</b>, if the data set has only
  1159. two labels +1 and -1,
  1160. internally we ensure +1 to be before -1. Then class +1
  1161. is always treated as positive in the SVM problem.
  1162. Note that this is for <b>two-class data only.</b>
  1163. <p align="right">
  1164. <a href="#_TOP">[Go Top]</a>
  1165. <hr/>
  1166. <a name="/Q04:_Training_and_prediction"></a>
  1167. <a name="f431"><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>
  1168. <br/>
  1169. <p>Any value is ok. In this situation, what you will use is the output file of svm-predict, which gives predicted class labels.
  1170. <p align="right">
  1171. <a href="#_TOP">[Go Top]</a>
  1172. <hr/>
  1173. <a name="/Q04:_Training_and_prediction"></a>
  1174. <a name="f432"><b>Q: How can I use OpenMP to parallelize LIBSVM on a multicore/shared-memory computer?</b></a>
  1175. <br/>
  1176. <p>It is very easy if you are using GCC 4.2
  1177. or after.
  1178. <p> In Makefile, add -fopenmp to CFLAGS.
  1179. <p> In class SVC_Q of svm.cpp, modify the for loop
  1180. of get_Q to:
  1181. <pre>
  1182. #pragma omp parallel for private(j) schedule(guided)
  1183. for(j=start;j&lt;len;j++)
  1184. </pre>
  1185. <p> In the subroutine svm_predict_values of svm.cpp, add one line to the for loop:
  1186. <pre>
  1187. #pragma omp parallel for private(i) schedule(guided)
  1188. for(i=0;i&lt;l;i++)
  1189. kvalue[i] = Kernel::k_function(x,model-&gt;SV[i],model-&gt;param);
  1190. </pre>
  1191. For regression, you need to modify
  1192. class SVR_Q instead. The loop in svm_predict_values
  1193. is also different because you need
  1194. a reduction clause for the variable sum:
  1195. <pre>
  1196. #pragma omp parallel for private(i) reduction(+:sum) schedule(guided)
  1197. for(i=0;i&lt;model->l;i++)
  1198. sum += sv_coef[i] * Kernel::k_function(x,model-&gt;SV[i],model-&gt;param);
  1199. </pre>
  1200. <p> Then rebuild the package. Kernel evaluations in training/testing will be parallelized. An example of running this modification on
  1201. an 8-core machine using the data set
  1202. <a href=../libsvmtools/datasets/binary/real-sim.bz2>real-sim</a>:
  1203. <p> 8 cores:
  1204. <pre>
  1205. %setenv OMP_NUM_THREADS 8
  1206. %time svm-train -c 8 -g 0.5 -m 1000 real-sim
  1207. 175.90sec
  1208. </pre>
  1209. 1 core:
  1210. <pre>
  1211. %setenv OMP_NUM_THREADS 1
  1212. %time svm-train -c 8 -g 0.5 -m 1000 real-sim
  1213. 588.89sec
  1214. </pre>
  1215. For this data, kernel evaluations take 91% of training time. In the above example, we assume you use csh. For bash, use
  1216. <pre>
  1217. export OMP_NUM_THREADS=8
  1218. </pre>
  1219. instead.
  1220. <p> For Python interface, you need to add the -lgomp link option:
  1221. <pre>
  1222. $(CXX) -lgomp -shared -dynamiclib svm.o -o libsvm.so.$(SHVER)
  1223. </pre>
  1224. <p> For MS Windows, you need to add /openmp in CFLAGS of Makefile.win
  1225. <p align="right">
  1226. <a href="#_TOP">[Go Top]</a>
  1227. <hr/>
  1228. <a name="/Q04:_Training_and_prediction"></a>
  1229. <a name="f433"><b>Q: How could I know which training instances are support vectors?</b></a>
  1230. <br/>
  1231. <p>
  1232. It's very simple. Since version 3.13, you can use the function
  1233. <pre>
  1234. void svm_get_sv_indices(const struct svm_model *model, int *sv_indices)
  1235. </pre>
  1236. to get indices of support vectors. For example, in svm-train.c, after
  1237. <pre>
  1238. model = svm_train(&amp;prob, &amp;param);
  1239. </pre>
  1240. you can add
  1241. <pre>
  1242. int nr_sv = svm_get_nr_sv(model);
  1243. int *sv_indices = Malloc(int, nr_sv);
  1244. svm_get_sv_indices(model, sv_indices);
  1245. for (int i=0; i&lt;nr_sv; i++)
  1246. printf("instance %d is a support vector\n", sv_indices[i]);
  1247. </pre>
  1248. <p> If you use matlab interface, you can directly check
  1249. <pre>
  1250. model.sv_indices
  1251. </pre>
  1252. <p align="right">
  1253. <a href="#_TOP">[Go Top]</a>
  1254. <hr/>
  1255. <a name="/Q04:_Training_and_prediction"></a>
  1256. <a name="f434"><b>Q: Why sv_indices (indices of support vectors) are not stored in the saved model file?</b></a>
  1257. <br/>
  1258. <p>
  1259. Although sv_indices is a member of the model structure
  1260. to
  1261. indicate support vectors in the training set,
  1262. we do not store its contents in the model file.
  1263. The model file is mainly used in the future for
  1264. prediction, so it is basically <b>independent</b>
  1265. from training data. Thus
  1266. storing sv_indices is not necessary.
  1267. Users should find support vectors right after
  1268. the training process. See the previous FAQ.
  1269. <p align="right">
  1270. <a href="#_TOP">[Go Top]</a>
  1271. <hr/>
  1272. <a name="/Q05:_Cross_validation_and_parameter_selection"></a>
  1273. <a name="f501"><b>Q: After doing cross validation, why there is no model file outputted ?</b></a>
  1274. <br/>
  1275. <p>
  1276. Cross validation is used for selecting good parameters.
  1277. After finding them, you want to re-train the whole
  1278. data without the -v option.
  1279. <p align="right">
  1280. <a href="#_TOP">[Go Top]</a>
  1281. <hr/>
  1282. <a name="/Q05:_Cross_validation_and_parameter_selection"></a>
  1283. <a name="f502"><b>Q: Why my cross-validation results are different from those in the Practical Guide?</b></a>
  1284. <br/>
  1285. <p>
  1286. Due to random partitions of
  1287. the data, on different systems CV accuracy values
  1288. may be different.
  1289. <p align="right">
  1290. <a href="#_TOP">[Go Top]</a>
  1291. <hr/>
  1292. <a name="/Q05:_Cross_validation_and_parameter_selection"></a>
  1293. <a name="f503"><b>Q: On some systems CV accuracy is the same in several runs. How could I use different data partitions? In other words, how do I set random seed in LIBSVM?</b></a>
  1294. <br/>
  1295. <p>
  1296. If you use GNU C library,
  1297. the default seed 1 is considered. Thus you always
  1298. get the same result of running svm-train -v.
  1299. To have different seeds, you can add the following code
  1300. in svm-train.c:
  1301. <pre>
  1302. #include &lt;time.h&gt;
  1303. </pre>
  1304. and in the beginning of main(),
  1305. <pre>
  1306. srand(time(0));
  1307. </pre>
  1308. Alternatively, if you are not using GNU C library
  1309. and would like to use a fixed seed, you can have
  1310. <pre>
  1311. srand(1);
  1312. </pre>
  1313. <p>
  1314. For Java, the random number generator
  1315. is initialized using the time information.
  1316. So results of two CV runs are different.
  1317. To fix the seed, after version 3.1 (released
  1318. in mid 2011), you can add
  1319. <pre>
  1320. svm.rand.setSeed(0);
  1321. </pre>
  1322. in the main() function of svm_train.java.
  1323. <p>
  1324. If you use CV to select parameters, it is recommended to use identical folds
  1325. under different parameters. In this case, you can consider fixing the seed.
  1326. <p align="right">
  1327. <a href="#_TOP">[Go Top]</a>
  1328. <hr/>
  1329. <a name="/Q05:_Cross_validation_and_parameter_selection"></a>
  1330. <a name="f504"><b>Q: Why on windows sometimes grid.py fails?</b></a>
  1331. <br/>
  1332. <p>
  1333. This problem shouldn't happen after version
  1334. 2.85. If you are using earlier versions,
  1335. please download the latest one.
  1336. <!--
  1337. <p>
  1338. If you are using earlier
  1339. versions, the error message is probably
  1340. <pre>
  1341. Traceback (most recent call last):
  1342. File "grid.py", line 349, in ?
  1343. main()
  1344. File "grid.py", line 344, in main
  1345. redraw(db)
  1346. File "grid.py", line 132, in redraw
  1347. gnuplot.write("set term windows\n")
  1348. IOError: [Errno 22] Invalid argument
  1349. </pre>
  1350. <p>Please try to close gnuplot windows and rerun.
  1351. If the problem still occurs, comment the following
  1352. two lines in grid.py by inserting "#" in the beginning:
  1353. <pre>
  1354. redraw(db)
  1355. redraw(db,1)
  1356. </pre>
  1357. Then you get accuracy only but not cross validation contours.
  1358. -->
  1359. <p align="right">
  1360. <a href="#_TOP">[Go Top]</a>
  1361. <hr/>
  1362. <a name="/Q05:_Cross_validation_and_parameter_selection"></a>
  1363. <a name="f505"><b>Q: Why grid.py/easy.py sometimes generates the following warning message?</b></a>
  1364. <br/>
  1365. <pre>
  1366. Warning: empty z range [62.5:62.5], adjusting to [61.875:63.125]
  1367. Notice: cannot contour non grid data!
  1368. </pre>
  1369. <p>Nothing is wrong and please disregard the
  1370. message. It is from gnuplot when drawing
  1371. the contour.
  1372. <p align="right">
  1373. <a href="#_TOP">[Go Top]</a>
  1374. <hr/>
  1375. <a name="/Q05:_Cross_validation_and_parameter_selection"></a>
  1376. <a name="f506"><b>Q: How do I choose the kernel?</b></a>
  1377. <br/>
  1378. <p>
  1379. In general we suggest you to try the RBF kernel first.
  1380. A recent result by Keerthi and Lin
  1381. (<a href=http://www.csie.ntu.edu.tw/~cjlin/papers/limit.pdf>
  1382. download paper here</a>)
  1383. shows that if RBF is used with model selection,
  1384. then there is no need to consider the linear kernel.
  1385. The kernel matrix using sigmoid may not be positive definite
  1386. and in general it's accuracy is not better than RBF.
  1387. (see the paper by Lin and Lin
  1388. (<a href=http://www.csie.ntu.edu.tw/~cjlin/papers/tanh.pdf>
  1389. download paper here</a>).
  1390. Polynomial kernels are ok but if a high degree is used,
  1391. numerical difficulties tend to happen
  1392. (thinking about dth power of (<1) goes to 0
  1393. and (>1) goes to infinity).
  1394. <p align="right">
  1395. <a href="#_TOP">[Go Top]</a>
  1396. <hr/>
  1397. <a name="/Q05:_Cross_validation_and_parameter_selection"></a>
  1398. <a name="f507"><b>Q: How does LIBSVM perform parameter selection for multi-class problems? </b></a>
  1399. <br/>
  1400. <p>
  1401. LIBSVM implements "one-against-one" multi-class method, so there are
  1402. k(k-1)/2 binary models, where k is the number of classes.
  1403. <p>
  1404. We can consider two ways to conduct parameter selection.
  1405. <ol>
  1406. <li>
  1407. For any two classes of data, a parameter selection procedure is conducted. Finally,
  1408. each decision function has its own optimal parameters.
  1409. </li>
  1410. <li>
  1411. The same parameters are used for all k(k-1)/2 binary classification problems.
  1412. We select parameters that achieve the highest overall performance.
  1413. </li>
  1414. </ol>
  1415. Each has its own advantages. A
  1416. single parameter set may not be uniformly good for all k(k-1)/2 decision functions.
  1417. However, as the overall accuracy is the final consideration, one parameter set
  1418. for one decision function may lead to over-fitting. In the paper
  1419. <p>
  1420. Chen, Lin, and Sch&ouml;lkopf,
  1421. <A HREF="../papers/nusvmtutorial.pdf">
  1422. A tutorial on nu-support vector machines.
  1423. </A>
  1424. Applied Stochastic Models in Business and Industry, 21(2005), 111-136,
  1425. <p>
  1426. they have experimentally
  1427. shown that the two methods give similar performance.
  1428. Therefore, currently the parameter selection in LIBSVM
  1429. takes the second approach by considering the same parameters for
  1430. all k(k-1)/2 models.
  1431. <p align="right">
  1432. <a href="#_TOP">[Go Top]</a>
  1433. <hr/>
  1434. <a name="/Q05:_Cross_validation_and_parameter_selection"></a>
  1435. <a name="f508"><b>Q: How do I choose parameters for one-class SVM as training data are in only one class?</b></a>
  1436. <br/>
  1437. <p>
  1438. You have pre-specified true positive rate in mind and then search for
  1439. parameters which achieve similar cross-validation accuracy.
  1440. <p align="right">
  1441. <a href="#_TOP">[Go Top]</a>
  1442. <hr/>
  1443. <a name="/Q05:_Cross_validation_and_parameter_selection"></a>
  1444. <a name="f509"><b>Q: Instead of grid.py, what if I would like to conduct parameter selection using other programmin languages?</b></a>
  1445. <br/>
  1446. <p>
  1447. For MATLAB, please see another question in FAQ.
  1448. <p>
  1449. For using shell scripts, please check the <a href=https://github.com/ljos/svm-grid>code</a> written by Bjarte Johansen
  1450. <p align="right">
  1451. <a href="#_TOP">[Go Top]</a>
  1452. <hr/>
  1453. <a name="/Q06:_Probability_outputs"></a>
  1454. <a name="f425"><b>Q: Why training a probability model (i.e., -b 1) takes a longer time?</b></a>
  1455. <br/>
  1456. <p>
  1457. To construct this probability model, we internally conduct a
  1458. cross validation, which is more time consuming than
  1459. a regular training.
  1460. Hence, in general you do parameter selection first without
  1461. -b 1. You only use -b 1 when good parameters have been
  1462. selected. In other words, you avoid using -b 1 and -v
  1463. together.
  1464. <p align="right">
  1465. <a href="#_TOP">[Go Top]</a>
  1466. <hr/>
  1467. <a name="/Q06:_Probability_outputs"></a>
  1468. <a name="f426"><b>Q: Why using the -b option does not give me better accuracy?</b></a>
  1469. <br/>
  1470. <p>
  1471. There is absolutely no reason the probability outputs guarantee
  1472. you better accuracy. The main purpose of this option is
  1473. to provide you the probability estimates, but not to boost
  1474. prediction accuracy. From our experience,
  1475. after proper parameter selections, in general with
  1476. and without -b have similar accuracy. Occasionally there
  1477. are some differences.
  1478. It is not recommended to compare the two under
  1479. just a fixed parameter
  1480. set as more differences will be observed.
  1481. <p align="right">
  1482. <a href="#_TOP">[Go Top]</a>
  1483. <hr/>
  1484. <a name="/Q06:_Probability_outputs"></a>
  1485. <a name="f427"><b>Q: Why using svm-predict -b 0 and -b 1 gives different accuracy values?</b></a>
  1486. <br/>
  1487. <p>
  1488. Let's just consider two-class classification here. After probability information is obtained in training,
  1489. we do not have
  1490. <p>
  1491. prob > = 0.5 if and only if decision value >= 0.
  1492. <p>
  1493. So predictions may be different with -b 0 and 1.
  1494. <p align="right">
  1495. <a href="#_TOP">[Go Top]</a>
  1496. <hr/>
  1497. <a name="/Q07:_Graphic_interface"></a>
  1498. <a name="f501"><b>Q: How can I save images drawn by svm-toy?</b></a>
  1499. <br/>
  1500. <p>
  1501. For Microsoft windows, first press the "print screen" key on the keyboard.
  1502. Open "Microsoft Paint"
  1503. (included in Windows)
  1504. and press "ctrl-v." Then you can clip
  1505. the part of picture which you want.
  1506. For X windows, you can
  1507. use the program "xv" or "import" to grab the picture of the svm-toy window.
  1508. <p align="right">
  1509. <a href="#_TOP">[Go Top]</a>
  1510. <hr/>
  1511. <a name="/Q07:_Graphic_interface"></a>
  1512. <a name="f502"><b>Q: I press the "load" button to load data points but why svm-toy does not draw them ?</b></a>
  1513. <br/>
  1514. <p>
  1515. The program svm-toy assumes both attributes (i.e. x-axis and y-axis
  1516. values) are in (0,1). Hence you want to scale your
  1517. data to between a small positive number and
  1518. a number less than but very close to 1.
  1519. Moreover, class labels must be 1, 2, or 3
  1520. (not 1.0, 2.0 or anything else).
  1521. <p align="right">
  1522. <a href="#_TOP">[Go Top]</a>
  1523. <hr/>
  1524. <a name="/Q07:_Graphic_interface"></a>
  1525. <a name="f503"><b>Q: I would like svm-toy to handle more than three classes of data, what should I do ?</b></a>
  1526. <br/>
  1527. <p>
  1528. Taking windows/svm-toy.cpp as an example, you need to
  1529. modify it and the difference
  1530. from the original file is as the following: (for five classes of
  1531. data)
  1532. <pre>
  1533. 30,32c30
  1534. < RGB(200,0,200),
  1535. < RGB(0,160,0),
  1536. < RGB(160,0,0)
  1537. ---
  1538. > RGB(200,0,200)
  1539. 39c37
  1540. < HBRUSH brush1, brush2, brush3, brush4, brush5;
  1541. ---
  1542. > HBRUSH brush1, brush2, brush3;
  1543. 113,114d110
  1544. < brush4 = CreateSolidBrush(colors[7]);
  1545. < brush5 = CreateSolidBrush(colors[8]);
  1546. 155,157c151
  1547. < else if(v==3) return brush3;
  1548. < else if(v==4) return brush4;
  1549. < else return brush5;
  1550. ---
  1551. > else return brush3;
  1552. 325d318
  1553. < int colornum = 5;
  1554. 327c320
  1555. < svm_node *x_space = new svm_node[colornum * prob.l];
  1556. ---
  1557. > svm_node *x_space = new svm_node[3 * prob.l];
  1558. 333,338c326,331
  1559. < x_space[colornum * i].index = 1;
  1560. < x_space[colornum * i].value = q->x;
  1561. < x_space[colornum * i + 1].index = 2;
  1562. < x_space[colornum * i + 1].value = q->y;
  1563. < x_space[colornum * i + 2].index = -1;
  1564. < prob.x[i] = &x_space[colornum * i];
  1565. ---
  1566. > x_space[3 * i].index = 1;
  1567. > x_space[3 * i].value = q->x;
  1568. > x_space[3 * i + 1].index = 2;
  1569. > x_space[3 * i + 1].value = q->y;
  1570. > x_space[3 * i + 2].index = -1;
  1571. > prob.x[i] = &x_space[3 * i];
  1572. 397c390
  1573. < if(current_value > 5) current_value = 1;
  1574. ---
  1575. > if(current_value > 3) current_value = 1;
  1576. </pre>
  1577. <p align="right">
  1578. <a href="#_TOP">[Go Top]</a>
  1579. <hr/>
  1580. <a name="/Q08:_Java_version_of_libsvm"></a>
  1581. <a name="f601"><b>Q: What is the difference between Java version and C++ version of libsvm?</b></a>
  1582. <br/>
  1583. <p>
  1584. They are the same thing. We just rewrote the C++ code
  1585. in Java.
  1586. <p align="right">
  1587. <a href="#_TOP">[Go Top]</a>
  1588. <hr/>
  1589. <a name="/Q08:_Java_version_of_libsvm"></a>
  1590. <a name="f602"><b>Q: Is the Java version significantly slower than the C++ version?</b></a>
  1591. <br/>
  1592. <p>
  1593. This depends on the VM you used. We have seen good
  1594. VM which leads the Java version to be quite competitive with
  1595. the C++ code. (though still slower)
  1596. <p align="right">
  1597. <a href="#_TOP">[Go Top]</a>
  1598. <hr/>
  1599. <a name="/Q08:_Java_version_of_libsvm"></a>
  1600. <a name="f603"><b>Q: While training I get the following error message: java.lang.OutOfMemoryError. What is wrong?</b></a>
  1601. <br/>
  1602. <p>
  1603. You should try to increase the maximum Java heap size.
  1604. For example,
  1605. <pre>
  1606. java -Xmx2048m -classpath libsvm.jar svm_train ...
  1607. </pre>
  1608. sets the maximum heap size to 2048M.
  1609. <p align="right">
  1610. <a href="#_TOP">[Go Top]</a>
  1611. <hr/>
  1612. <a name="/Q08:_Java_version_of_libsvm"></a>
  1613. <a name="f604"><b>Q: Why you have the main source file svm.m4 and then transform it to svm.java?</b></a>
  1614. <br/>
  1615. <p>
  1616. Unlike C, Java does not have a preprocessor built-in.
  1617. However, we need some macros (see first 3 lines of svm.m4).
  1618. </ul>
  1619. <p align="right">
  1620. <a href="#_TOP">[Go Top]</a>
  1621. <hr/>
  1622. <a name="/Q09:_Python_interface"></a>
  1623. <a name="f704"><b>Q: Except the python-C++ interface provided, could I use Jython to call libsvm ?</b></a>
  1624. <br/>
  1625. <p> Yes, here are some examples:
  1626. <pre>
  1627. $ export CLASSPATH=$CLASSPATH:~/libsvm-2.91/java/libsvm.jar
  1628. $ ./jython
  1629. Jython 2.1a3 on java1.3.0 (JIT: jitc)
  1630. Type "copyright", "credits" or "license" for more information.
  1631. >>> from libsvm import *
  1632. >>> dir()
  1633. ['__doc__', '__name__', 'svm', 'svm_model', 'svm_node', 'svm_parameter',
  1634. 'svm_problem']
  1635. >>> x1 = [svm_node(index=1,value=1)]
  1636. >>> x2 = [svm_node(index=1,value=-1)]
  1637. >>> param = svm_parameter(svm_type=0,kernel_type=2,gamma=1,cache_size=40,eps=0.001,C=1,nr_weight=0,shrinking=1)
  1638. >>> prob = svm_problem(l=2,y=[1,-1],x=[x1,x2])
  1639. >>> model = svm.svm_train(prob,param)
  1640. *
  1641. optimization finished, #iter = 1
  1642. nu = 1.0
  1643. obj = -1.018315639346838, rho = 0.0
  1644. nSV = 2, nBSV = 2
  1645. Total nSV = 2
  1646. >>> svm.svm_predict(model,x1)
  1647. 1.0
  1648. >>> svm.svm_predict(model,x2)
  1649. -1.0
  1650. >>> svm.svm_save_model("test.model",model)
  1651. </pre>
  1652. <p align="right">
  1653. <a href="#_TOP">[Go Top]</a>
  1654. <hr/>
  1655. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1656. <a name="f801"><b>Q: I compile the MATLAB interface without problem, but why errors occur while running it?</b></a>
  1657. <br/>
  1658. <p>
  1659. Your compiler version may not be supported/compatible for MATLAB.
  1660. Please check <a href=http://www.mathworks.com/support/compilers/current_release>this MATLAB page</a> first and then specify the version
  1661. number. For example, if g++ X.Y is supported, replace
  1662. <pre>
  1663. CXX = g++
  1664. </pre>
  1665. in the Makefile with
  1666. <pre>
  1667. CXX = g++-X.Y
  1668. </pre>
  1669. <p align="right">
  1670. <a href="#_TOP">[Go Top]</a>
  1671. <hr/>
  1672. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1673. <a name="f8011"><b>Q: On 64bit Windows I compile the MATLAB interface without problem, but why errors occur while running it?</b></a>
  1674. <br/>
  1675. <p>
  1676. Please make sure that you use
  1677. the -largeArrayDims option in make.m. For example,
  1678. <pre>
  1679. mex -largeArrayDims -O -c svm.cpp
  1680. </pre>
  1681. Moreover, if you use Microsoft Visual Studio,
  1682. probabally it is not properly installed.
  1683. See the explanation
  1684. <a href=http://www.mathworks.com/support/compilers/current_release/win64.html#n7>here</a>.
  1685. <p align="right">
  1686. <a href="#_TOP">[Go Top]</a>
  1687. <hr/>
  1688. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1689. <a name="f802"><b>Q: Does the MATLAB interface provide a function to do scaling?</b></a>
  1690. <br/>
  1691. <p>
  1692. It is extremely easy to do scaling under MATLAB.
  1693. The following one-line code scale each feature to the range
  1694. of [0,1]:
  1695. <pre>
  1696. (data - repmat(min(data,[],1),size(data,1),1))*spdiags(1./(max(data,[],1)-min(data,[],1))',0,size(data,2),size(data,2))
  1697. </pre>
  1698. <p align="right">
  1699. <a href="#_TOP">[Go Top]</a>
  1700. <hr/>
  1701. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1702. <a name="f803"><b>Q: How could I use MATLAB interface for parameter selection?</b></a>
  1703. <br/>
  1704. <p>
  1705. One can do this by a simple loop.
  1706. See the following example:
  1707. <pre>
  1708. bestcv = 0;
  1709. for log2c = -1:3,
  1710. for log2g = -4:1,
  1711. cmd = ['-v 5 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
  1712. cv = svmtrain(heart_scale_label, heart_scale_inst, cmd);
  1713. if (cv >= bestcv),
  1714. bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
  1715. end
  1716. fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
  1717. end
  1718. end
  1719. </pre>
  1720. You may adjust the parameter range in the above loops.
  1721. <p align="right">
  1722. <a href="#_TOP">[Go Top]</a>
  1723. <hr/>
  1724. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1725. <a name="f8031"><b>Q: I use MATLAB parallel programming toolbox on a multi-core environment for parameter selection. Why the program is even slower?</b></a>
  1726. <br/>
  1727. <p>
  1728. Fabrizio Lacalandra of University of Pisa reported this issue.
  1729. It seems the problem is caused by the screen output.
  1730. If you disable the <b>info</b> function
  1731. using <pre>#if 0,</pre> then the problem
  1732. may be solved.
  1733. <p align="right">
  1734. <a href="#_TOP">[Go Top]</a>
  1735. <hr/>
  1736. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1737. <a name="f8032"><b>Q: How to use LIBSVM with OpenMP under MATLAB/Octave?</b></a>
  1738. <br/>
  1739. <p>
  1740. First, you must modify svm.cpp. Check the following faq,
  1741. <a href="faq.html#f432">How can I use OpenMP to parallelize LIBSVM on a multicore/shared-memory computer?</a>
  1742. <p>
  1743. To build the MATLAB/Octave interface, we recommend using <b>make.m</b>.
  1744. You must append '-fopenmp' to CXXFLAGS and add '-lgomp' to mex options in <b>make.m</b>.
  1745. See details below.
  1746. <p>
  1747. For MATLAB users, the modified code is:
  1748. <pre>
  1749. mex CFLAGS="\$CFLAGS -std=c99" CXXFLAGS="\$CXXFLAGS -fopenmp" -largeArrayDims -I.. -lgomp svmtrain.c ../svm.cpp svm_model_matlab.c
  1750. mex CFLAGS="\$CFLAGS -std=c99" CXXFLAGS="\$CXXFLAGS -fopenmp" -largeArrayDims -I.. -lgomp svmpredict.c ../svm.cpp svm_model_matlab.c
  1751. </pre>
  1752. <p>
  1753. For Octave users, the modified code is:
  1754. <pre>
  1755. setenv('CXXFLAGS', '-fopenmp')
  1756. mex -I.. -lgomp svmtrain.c ../svm.cpp svm_model_matlab.c
  1757. mex -I.. -lgomp svmpredict.c ../svm.cpp svm_model_matlab.c
  1758. </pre>
  1759. <p>
  1760. If make.m fails under matlab and you use <b>Makefile</b> to compile the codes,
  1761. you must modify <b>two</b> files:
  1762. <p>
  1763. You must append '-fopenmp' to CFLAGS in <b>../Makefile</b> for C/C++ codes:
  1764. <pre>
  1765. CFLAGS = -Wall -Wconversion -O3 -fPIC -fopenmp -I$(MATLABDIR)/extern/include -I..
  1766. </pre>
  1767. and add '-lgomp' to MEX_OPTION in <b>Makefile</b> for the matlab/octave interface:
  1768. <pre>
  1769. MEX_OPTION += -lgomp
  1770. </pre>
  1771. <p>
  1772. To run the code, you must specify the number of threads. For
  1773. example, <b>before</b> executing matlab/octave, you run
  1774. <pre>
  1775. > export OMP_NUM_THREADS=8
  1776. > matlab
  1777. </pre>
  1778. Here we assume Bash is used. Unfortunately, we do not know yet
  1779. how to specify the number of threads within MATLAB/Octave. Our
  1780. experiments show that
  1781. <pre>
  1782. >> setenv('OMP_NUM_THREADS', '8');
  1783. </pre>
  1784. does not work. Please contact us if you
  1785. see how to solve this problem. On the other hand, you can
  1786. specify the number of threads in the source code (thanks
  1787. to comments from Ricardo Santiago-mozos):
  1788. <pre>
  1789. #pragma omp parallel for private(i) num_threads(8)
  1790. </pre>
  1791. <p align="right">
  1792. <a href="#_TOP">[Go Top]</a>
  1793. <hr/>
  1794. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1795. <a name="f804"><b>Q: How could I generate the primal variable w of linear SVM?</b></a>
  1796. <br/>
  1797. <p>
  1798. Let's start from the binary class and
  1799. assume you have two labels -1 and +1.
  1800. After obtaining the model from calling svmtrain,
  1801. do the following to have w and b:
  1802. <pre>
  1803. w = model.SVs' * model.sv_coef;
  1804. b = -model.rho;
  1805. if model.Label(1) == -1
  1806. w = -w;
  1807. b = -b;
  1808. end
  1809. </pre>
  1810. If you do regression or one-class SVM, then the if statement is not needed.
  1811. <p> For multi-class SVM, we illustrate the setting
  1812. in the following example of running the iris
  1813. data, which have 3 classes
  1814. <pre>
  1815. > [y, x] = libsvmread('../../htdocs/libsvmtools/datasets/multiclass/iris.scale');
  1816. > m = svmtrain(y, x, '-t 0')
  1817. m =
  1818. Parameters: [5x1 double]
  1819. nr_class: 3
  1820. totalSV: 42
  1821. rho: [3x1 double]
  1822. Label: [3x1 double]
  1823. ProbA: []
  1824. ProbB: []
  1825. nSV: [3x1 double]
  1826. sv_coef: [42x2 double]
  1827. SVs: [42x4 double]
  1828. </pre>
  1829. sv_coef is like:
  1830. <pre>
  1831. +-+-+--------------------+
  1832. |1|1| |
  1833. |v|v| SVs from class 1 |
  1834. |2|3| |
  1835. +-+-+--------------------+
  1836. |1|2| |
  1837. |v|v| SVs from class 2 |
  1838. |2|3| |
  1839. +-+-+--------------------+
  1840. |1|2| |
  1841. |v|v| SVs from class 3 |
  1842. |3|3| |
  1843. +-+-+--------------------+
  1844. </pre>
  1845. so we need to see nSV of each classes.
  1846. <pre>
  1847. > m.nSV
  1848. ans =
  1849. 3
  1850. 21
  1851. 18
  1852. </pre>
  1853. Suppose the goal is to find the vector w of classes
  1854. 1 vs 3. Then
  1855. y_i alpha_i of training 1 vs 3 are
  1856. <pre>
  1857. > coef = [m.sv_coef(1:3,2); m.sv_coef(25:42,1)];
  1858. </pre>
  1859. and SVs are:
  1860. <pre>
  1861. > SVs = [m.SVs(1:3,:); m.SVs(25:42,:)];
  1862. </pre>
  1863. Hence, w is
  1864. <pre>
  1865. > w = SVs'*coef;
  1866. </pre>
  1867. For rho,
  1868. <pre>
  1869. > m.rho
  1870. ans =
  1871. 1.1465
  1872. 0.3682
  1873. -1.9969
  1874. > b = -m.rho(2);
  1875. </pre>
  1876. because rho is arranged by 1vs2 1vs3 2vs3.
  1877. <p align="right">
  1878. <a href="#_TOP">[Go Top]</a>
  1879. <hr/>
  1880. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1881. <a name="f805"><b>Q: Is there an OCTAVE interface for libsvm?</b></a>
  1882. <br/>
  1883. <p>
  1884. Yes, after libsvm 2.86, the matlab interface
  1885. works on OCTAVE as well. Please use make.m by typing
  1886. <pre>
  1887. >> make
  1888. </pre>
  1889. under OCTAVE.
  1890. <p align="right">
  1891. <a href="#_TOP">[Go Top]</a>
  1892. <hr/>
  1893. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1894. <a name="f806"><b>Q: How to handle the name conflict between svmtrain in the libsvm matlab interface and that in MATLAB bioinformatics toolbox?</b></a>
  1895. <br/>
  1896. <p>
  1897. The easiest way is to rename the svmtrain binary
  1898. file (e.g., svmtrain.mexw32 on 32-bit windows)
  1899. to a different
  1900. name (e.g., svmtrain2.mexw32).
  1901. <p align="right">
  1902. <a href="#_TOP">[Go Top]</a>
  1903. <hr/>
  1904. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1905. <a name="f807"><b>Q: On Windows I got an error message "Invalid MEX-file: Specific module not found" when running the pre-built MATLAB interface in the windows sub-directory. What should I do?</b></a>
  1906. <br/>
  1907. <p>
  1908. The error usually happens
  1909. when there are missing runtime components
  1910. such as MSVCR100.dll on your Windows platform.
  1911. You can use tools such as
  1912. <a href=http://www.dependencywalker.com/>Dependency
  1913. Walker</a> to find missing library files.
  1914. <p>
  1915. For example, if the pre-built MEX files are compiled by
  1916. Visual C++ 2010,
  1917. you must have installed
  1918. Microsoft Visual C++ Redistributable Package 2010
  1919. (vcredist_x86.exe). You can easily find the freely
  1920. available file from Microsoft's web site.
  1921. <p>
  1922. For 64bit Windows, the situation is similar. If
  1923. the pre-built files are by
  1924. Visual C++ 2008, then you must have
  1925. Microsoft Visual C++ Redistributable Package 2008
  1926. (vcredist_x64.exe).
  1927. <p align="right">
  1928. <a href="#_TOP">[Go Top]</a>
  1929. <hr/>
  1930. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1931. <a name="f808"><b>Q: LIBSVM supports 1-vs-1 multi-class classification. If instead I would like to use 1-vs-rest, how to implement it using MATLAB interface?</b></a>
  1932. <br/>
  1933. <p>
  1934. Please use code in the following <a href=../libsvmtools/ovr_multiclass>directory</a>. The following example shows how to
  1935. train and test the problem dna (<a href=../libsvmtools/datasets/multiclass/dna.scale>training</a> and <a href=../libsvmtools/datasets/multiclass/dna.scale.t>testing</a>).
  1936. <p> Load, train and predict data:
  1937. <pre>
  1938. [trainY trainX] = libsvmread('./dna.scale');
  1939. [testY testX] = libsvmread('./dna.scale.t');
  1940. model = ovrtrain(trainY, trainX, '-c 8 -g 4');
  1941. [pred ac decv] = ovrpredict(testY, testX, model);
  1942. fprintf('Accuracy = %g%%\n', ac * 100);
  1943. </pre>
  1944. Conduct CV on a grid of parameters
  1945. <pre>
  1946. bestcv = 0;
  1947. for log2c = -1:2:3,
  1948. for log2g = -4:2:1,
  1949. cmd = ['-q -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
  1950. cv = get_cv_ac(trainY, trainX, cmd, 3);
  1951. if (cv >= bestcv),
  1952. bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
  1953. end
  1954. fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
  1955. end
  1956. end
  1957. </pre>
  1958. <p align="right">
  1959. <a href="#_TOP">[Go Top]</a>
  1960. <hr/>
  1961. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  1962. <a name="f809"><b>Q: I tried to install matlab interface on mac, but failed. What should I do?</b></a>
  1963. <br/>
  1964. <p>
  1965. We assume that in a matlab command window you change directory to libsvm/matlab and type
  1966. <pre>
  1967. >> make
  1968. </pre>
  1969. We discuss the following situations.
  1970. <ol>
  1971. <li>An error message like "libsvmread.c:1:19: fatal error:
  1972. stdio.h: No such file or directory" appears.
  1973. <p>
  1974. Reason: "make" looks for a C++ compiler, but
  1975. no compiler is found. To get one, you can
  1976. <ul>
  1977. <li> Install XCode offered by Apple Inc.
  1978. <li> Install XCode Command Line Tools.
  1979. </ul>
  1980. <p>
  1981. <li> On OS X with Xcode 4.2+, I got an error message like "llvm-gcc-4.2:
  1982. command not found."
  1983. <p>
  1984. Reason: Since Apple Inc. only ships llsvm-gcc instead of gcc-4.2,
  1985. llvm-gcc-4.2 cannot be found.
  1986. <p>
  1987. If you are using Xcode 4.2-4.6,
  1988. a related solution is offered at
  1989. <a href=http://www.mathworks.com/matlabcentral/answers/94092>http://www.mathworks.com/matlabcentral/answers/94092</a>.
  1990. <p>
  1991. On the other hand, for Xcode 5 (including Xcode 4.2-4.6), in a Matlab command window, enter
  1992. <ul>
  1993. <li> cd (matlabroot)
  1994. <li> cd bin
  1995. <li> Backup your mexopts.sh first
  1996. <li> edit mexopts.sh
  1997. <li> Scroll down to "maci64" section. Change
  1998. <pre>
  1999. CC='llvm-gcc-4.2'
  2000. CXX='llvm-g++-4.2'
  2001. </pre>
  2002. to
  2003. <pre>
  2004. CC='llvm-gcc'
  2005. CXX='llvm-g++'
  2006. </pre>
  2007. </ul>
  2008. Please also ensure that SDKROOT corresponds to the SDK version you are using.
  2009. <p>
  2010. <li> Other errors: you may check <a href=http://www.mathworks.com/matlabcentral/answers/94092>http://www.mathworks.com/matlabcentral/answers/94092</a>.
  2011. </ol>
  2012. <p align="right">
  2013. <a href="#_TOP">[Go Top]</a>
  2014. <hr/>
  2015. <a name="/Q10:_MATLAB_OCTAVE_interface"></a>
  2016. <a name="f810"><b>Q: I tried to install octave interface on windows, but failed. What should I do?</b></a>
  2017. <br/>
  2018. <p>
  2019. This may be due to
  2020. that Octave's math.h file does not
  2021. refer to the correct location of Visual Studio's math.h.
  2022. Please see <a href=https://flyingpies.wordpress.com/2012/11/20/getting-libsvm-to-work-with-octave-on-windows/>this nice page</a> for detailed
  2023. instructions.
  2024. <p align="right">
  2025. <a href="#_TOP">[Go Top]</a>
  2026. <hr/>
  2027. <p align="middle">
  2028. <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm">LIBSVM home page</a>
  2029. </p>
  2030. </body>
  2031. </html>

A Python package for graph kernels, graph edit distances and graph pre-image problem.