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.

README 9.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. -----------------------------------------
  2. --- MATLAB/OCTAVE interface of LIBSVM ---
  3. -----------------------------------------
  4. Table of Contents
  5. =================
  6. - Introduction
  7. - Installation
  8. - Usage
  9. - Returned Model Structure
  10. - Other Utilities
  11. - Examples
  12. - Additional Information
  13. Introduction
  14. ============
  15. This tool provides a simple interface to LIBSVM, a library for support vector
  16. machines (http://www.csie.ntu.edu.tw/~cjlin/libsvm). It is very easy to use as
  17. the usage and the way of specifying parameters are the same as that of LIBSVM.
  18. Installation
  19. ============
  20. On Windows systems, pre-built binary files are already in the
  21. directory '..\windows', so no need to conduct installation. Now we
  22. provide binary files only for 64bit MATLAB on Windows. If you would
  23. like to re-build the package, please rely on the following steps.
  24. We recommend using make.m on both MATLAB and OCTAVE. Just type 'make'
  25. to build 'libsvmread.mex', 'libsvmwrite.mex', 'svmtrain.mex', and
  26. 'svmpredict.mex'.
  27. On MATLAB or Octave:
  28. >> make
  29. If make.m does not work on MATLAB (especially for Windows), try 'mex
  30. -setup' to choose a suitable compiler for mex. Make sure your compiler
  31. is accessible and workable. Then type 'make' to start the
  32. installation.
  33. Example:
  34. matlab>> mex -setup
  35. (ps: MATLAB will show the following messages to setup default compiler.)
  36. Please choose your compiler for building external interface (MEX) files:
  37. Would you like mex to locate installed compilers [y]/n? y
  38. Select a compiler:
  39. [1] Microsoft Visual C/C++ version 7.1 in C:\Program Files\Microsoft Visual Studio
  40. [0] None
  41. Compiler: 1
  42. Please verify your choices:
  43. Compiler: Microsoft Visual C/C++ 7.1
  44. Location: C:\Program Files\Microsoft Visual Studio
  45. Are these correct?([y]/n): y
  46. matlab>> make
  47. On Unix systems, if neither make.m nor 'mex -setup' works, please use
  48. Makefile and type 'make' in a command window. Note that we assume
  49. your MATLAB is installed in '/usr/local/matlab'. If not, please change
  50. MATLABDIR in Makefile.
  51. Example:
  52. linux> make
  53. To use octave, type 'make octave':
  54. Example:
  55. linux> make octave
  56. For a list of supported/compatible compilers for MATLAB, please check
  57. the following page:
  58. http://www.mathworks.com/support/compilers/current_release/
  59. Usage
  60. =====
  61. matlab> model = svmtrain(training_label_vector, training_instance_matrix [, 'libsvm_options']);
  62. -training_label_vector:
  63. An m by 1 vector of training labels (type must be double).
  64. -training_instance_matrix:
  65. An m by n matrix of m training instances with n features.
  66. It can be dense or sparse (type must be double).
  67. -libsvm_options:
  68. A string of training options in the same format as that of LIBSVM.
  69. matlab> [predicted_label, accuracy, decision_values/prob_estimates] = svmpredict(testing_label_vector, testing_instance_matrix, model [, 'libsvm_options']);
  70. matlab> [predicted_label] = svmpredict(testing_label_vector, testing_instance_matrix, model [, 'libsvm_options']);
  71. -testing_label_vector:
  72. An m by 1 vector of prediction labels. If labels of test
  73. data are unknown, simply use any random values. (type must be double)
  74. -testing_instance_matrix:
  75. An m by n matrix of m testing instances with n features.
  76. It can be dense or sparse. (type must be double)
  77. -model:
  78. The output of svmtrain.
  79. -libsvm_options:
  80. A string of testing options in the same format as that of LIBSVM.
  81. Returned Model Structure
  82. ========================
  83. The 'svmtrain' function returns a model which can be used for future
  84. prediction. It is a structure and is organized as [Parameters, nr_class,
  85. totalSV, rho, Label, ProbA, ProbB, nSV, sv_coef, SVs]:
  86. -Parameters: parameters
  87. -nr_class: number of classes; = 2 for regression/one-class svm
  88. -totalSV: total #SV
  89. -rho: -b of the decision function(s) wx+b
  90. -Label: label of each class; empty for regression/one-class SVM
  91. -sv_indices: values in [1,...,num_traning_data] to indicate SVs in the training set
  92. -ProbA: pairwise probability information; empty if -b 0 or in one-class SVM
  93. -ProbB: pairwise probability information; empty if -b 0 or in one-class SVM
  94. -nSV: number of SVs for each class; empty for regression/one-class SVM
  95. -sv_coef: coefficients for SVs in decision functions
  96. -SVs: support vectors
  97. If you do not use the option '-b 1', ProbA and ProbB are empty
  98. matrices. If the '-v' option is specified, cross validation is
  99. conducted and the returned model is just a scalar: cross-validation
  100. accuracy for classification and mean-squared error for regression.
  101. More details about this model can be found in LIBSVM FAQ
  102. (http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html) and LIBSVM
  103. implementation document
  104. (http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf).
  105. Result of Prediction
  106. ====================
  107. The function 'svmpredict' has three outputs. The first one,
  108. predictd_label, is a vector of predicted labels. The second output,
  109. accuracy, is a vector including accuracy (for classification), mean
  110. squared error, and squared correlation coefficient (for regression).
  111. The third is a matrix containing decision values or probability
  112. estimates (if '-b 1' is specified). If k is the number of classes
  113. in training data, for decision values, each row includes results of
  114. predicting k(k-1)/2 binary-class SVMs. For classification, k = 1 is a
  115. special case. Decision value +1 is returned for each testing instance,
  116. instead of an empty vector. For probabilities, each row contains k values
  117. indicating the probability that the testing instance is in each class.
  118. Note that the order of classes here is the same as 'Label' field
  119. in the model structure.
  120. Other Utilities
  121. ===============
  122. A matlab function libsvmread reads files in LIBSVM format:
  123. [label_vector, instance_matrix] = libsvmread('data.txt');
  124. Two outputs are labels and instances, which can then be used as inputs
  125. of svmtrain or svmpredict.
  126. A matlab function libsvmwrite writes Matlab matrix to a file in LIBSVM format:
  127. libsvmwrite('data.txt', label_vector, instance_matrix)
  128. The instance_matrix must be a sparse matrix. (type must be double)
  129. For 32bit and 64bit MATLAB on Windows, pre-built binary files are ready
  130. in the directory `..\windows', but in future releases, we will only
  131. include 64bit MATLAB binary files.
  132. These codes are prepared by Rong-En Fan and Kai-Wei Chang from National
  133. Taiwan University.
  134. Examples
  135. ========
  136. Train and test on the provided data heart_scale:
  137. matlab> [heart_scale_label, heart_scale_inst] = libsvmread('../heart_scale');
  138. matlab> model = svmtrain(heart_scale_label, heart_scale_inst, '-c 1 -g 0.07');
  139. matlab> [predict_label, accuracy, dec_values] = svmpredict(heart_scale_label, heart_scale_inst, model); % test the training data
  140. For probability estimates, you need '-b 1' for training and testing:
  141. matlab> [heart_scale_label, heart_scale_inst] = libsvmread('../heart_scale');
  142. matlab> model = svmtrain(heart_scale_label, heart_scale_inst, '-c 1 -g 0.07 -b 1');
  143. matlab> [heart_scale_label, heart_scale_inst] = libsvmread('../heart_scale');
  144. matlab> [predict_label, accuracy, prob_estimates] = svmpredict(heart_scale_label, heart_scale_inst, model, '-b 1');
  145. To use precomputed kernel, you must include sample serial number as
  146. the first column of the training and testing data (assume your kernel
  147. matrix is K, # of instances is n):
  148. matlab> K1 = [(1:n)', K]; % include sample serial number as first column
  149. matlab> model = svmtrain(label_vector, K1, '-t 4');
  150. matlab> [predict_label, accuracy, dec_values] = svmpredict(label_vector, K1, model); % test the training data
  151. We give the following detailed example by splitting heart_scale into
  152. 150 training and 120 testing data. Constructing a linear kernel
  153. matrix and then using the precomputed kernel gives exactly the same
  154. testing error as using the LIBSVM built-in linear kernel.
  155. matlab> [heart_scale_label, heart_scale_inst] = libsvmread('../heart_scale');
  156. matlab>
  157. matlab> % Split Data
  158. matlab> train_data = heart_scale_inst(1:150,:);
  159. matlab> train_label = heart_scale_label(1:150,:);
  160. matlab> test_data = heart_scale_inst(151:270,:);
  161. matlab> test_label = heart_scale_label(151:270,:);
  162. matlab>
  163. matlab> % Linear Kernel
  164. matlab> model_linear = svmtrain(train_label, train_data, '-t 0');
  165. matlab> [predict_label_L, accuracy_L, dec_values_L] = svmpredict(test_label, test_data, model_linear);
  166. matlab>
  167. matlab> % Precomputed Kernel
  168. matlab> model_precomputed = svmtrain(train_label, [(1:150)', train_data*train_data'], '-t 4');
  169. matlab> [predict_label_P, accuracy_P, dec_values_P] = svmpredict(test_label, [(1:120)', test_data*train_data'], model_precomputed);
  170. matlab>
  171. matlab> accuracy_L % Display the accuracy using linear kernel
  172. matlab> accuracy_P % Display the accuracy using precomputed kernel
  173. Note that for testing, you can put anything in the
  174. testing_label_vector. For more details of precomputed kernels, please
  175. read the section ``Precomputed Kernels'' in the README of the LIBSVM
  176. package.
  177. Additional Information
  178. ======================
  179. This interface was initially written by Jun-Cheng Chen, Kuan-Jen Peng,
  180. Chih-Yuan Yang and Chih-Huai Cheng from Department of Computer
  181. Science, National Taiwan University. The current version was prepared
  182. by Rong-En Fan and Ting-Fan Wu. If you find this tool useful, please
  183. cite LIBSVM as follows
  184. Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for support
  185. vector machines. ACM Transactions on Intelligent Systems and
  186. Technology, 2:27:1--27:27, 2011. Software available at
  187. http://www.csie.ntu.edu.tw/~cjlin/libsvm
  188. For any question, please contact Chih-Jen Lin <cjlin@csie.ntu.edu.tw>,
  189. or check the FAQ page:
  190. http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html#/Q10:_MATLAB_interface

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