1. Libsvm is a simple, easy-to-use, and efficient software for SVM
  2. classification and regression. It solves C-SVM classification, nu-SVM
  3. classification, one-class-SVM, epsilon-SVM regression, and nu-SVM
  4. regression. It also provides an automatic model selection tool for
  5. C-SVM classification. This document explains the use of libsvm.
  6.  
  7. Libsvm is available at
  8. http://www.csie.ntu.edu.tw/~cjlin/libsvm
  9. Please read the COPYRIGHT file before using libsvm.
  10.  
  11. Table of Contents
  12. =================
  13.  
  14. - Quick Start
  15. - Installation and Data Format
  16. - `svm-train' Usage
  17. - `svm-predict' Usage
  18. - `svm-scale' Usage
  19. - Tips on Practical Use
  20. - Examples
  21. - Precomputed Kernels
  22. - Library Usage
  23. - Java Version
  24. - Building Windows Binaries
  25. - Additional Tools: Sub-sampling, Parameter Selection, Format checking, etc.
  26. - MATLAB/OCTAVE Interface
  27. - Python Interface
  28. - Additional Information
  29.  
  30. Quick Start
  31. ===========
  32.  
  33. If you are new to SVM and if the data is not large, please go to
  34. `tools' directory and use easy.py after installation. It does
  35. everything automatic -- from data scaling to parameter selection.
  36.  
  37. Usage: easy.py training_file [testing_file]
  38.  
  39. More information about parameter selection can be found in
  40. `tools/README.'
  41.  
  42. Installation and Data Format
  43. ============================
  44.  
  45. On Unix systems, type `make' to build the `svm-train' and `svm-predict'
  46. programs. Run them without arguments to show the usages of them.
  47.  
  48. On other systems, consult `Makefile' to build them (e.g., see
  49. 'Building Windows binaries' in this file) or use the pre-built
  50. binaries (Windows binaries are in the directory `windows').
  51.  
  52. The format of training and testing data file is:
  53.  
  54. <label> <index1>:<value1> <index2>:<value2> ...
  55. .
  56. .
  57. .
  58.  
  59. Each line contains an instance and is ended by a '\n' character. For
  60. classification, <label> is an integer indicating the class label
  61. (multi-class is supported). For regression, <label> is the target
  62. value which can be any real number. For one-class SVM, it's not used
  63. so can be any number. The pair <index>:<value> gives a feature
  64. (attribute) value: <index> is an integer starting from 1 and <value>
  65. is a real number. The only exception is the precomputed kernel, where
  66. <index> starts from 0; see the section of precomputed kernels. Indices
  67. must be in ASCENDING order. Labels in the testing file are only used
  68. to calculate accuracy or errors. If they are unknown, just fill the
  69. first column with any numbers.
  70.  
  71. A sample classification data included in this package is
  72. `heart_scale'. To check if your data is in a correct form, use
  73. `tools/checkdata.py' (details in `tools/README').
  74.  
  75. Type `svm-train heart_scale', and the program will read the training
  76. data and output the model file `heart_scale.model'. If you have a test
  77. set called heart_scale.t, then type `svm-predict heart_scale.t
  78. heart_scale.model output' to see the prediction accuracy. The `output'
  79. file contains the predicted class labels.
  80.  
  81. For classification, if training data are in only one class (i.e., all
  82. labels are the same), then `svm-train' issues a warning message:
  83. `Warning: training data in only one class. See README for details,'
  84. which means the training data is very unbalanced. The label in the
  85. training data is directly returned when testing.
  86.  
  87. There are some other useful programs in this package.
  88.  
  89. svm-scale:
  90.  
  91. This is a tool for scaling input data file.
  92.  
  93. svm-toy:
  94.  
  95. This is a simple graphical interface which shows how SVM
  96. separate data in a plane. You can click in the window to
  97. draw data points. Use "change" button to choose class
  98. 1, 2 or 3 (i.e., up to three classes are supported), "load"
  99. button to load data from a file, "save" button to save data to
  100. a file, "run" button to obtain an SVM model, and "clear"
  101. button to clear the window.
  102.  
  103. You can enter options in the bottom of the window, the syntax of
  104. options is the same as `svm-train'.
  105.  
  106. Note that "load" and "save" consider dense data format both in
  107. classification and the regression cases. For classification,
  108. each data point has one label (the color) that must be 1, 2,
  109. or 3 and two attributes (x-axis and y-axis values) in
  110. [0,1). For regression, each data point has one target value
  111. (y-axis) and one attribute (x-axis values) in [0, 1).
  112.  
  113. Type `make' in respective directories to build them.
  114.  
  115. You need Qt library to build the Qt version.
  116. (available from http://www.trolltech.com)
  117.  
  118. You need GTK+ library to build the GTK version.
  119. (available from http://www.gtk.org)
  120.  
  121. The pre-built Windows binaries are in the `windows'
  122. directory. We use Visual C++ on a 32-bit machine, so the
  123. maximal cache size is 2GB.
  124.  
  125. `svm-train' Usage
  126. =================
  127.  
  128. Usage: svm-train [options] training_set_file [model_file]
  129. options:
  130. -s svm_type : set type of SVM (default 0)
  131. 0 -- C-SVC (multi-class classification)
  132. 1 -- nu-SVC (multi-class classification)
  133. 2 -- one-class SVM
  134. 3 -- epsilon-SVR (regression)
  135. 4 -- nu-SVR (regression)
  136. -t kernel_type : set type of kernel function (default 2)
  137. 0 -- linear: u'*v
  138. 1 -- polynomial: (gamma*u'*v + coef0)^degree
  139. 2 -- radial basis function: exp(-gamma*|u-v|^2)
  140. 3 -- sigmoid: tanh(gamma*u'*v + coef0)
  141. 4 -- precomputed kernel (kernel values in training_set_file)
  142. -d degree : set degree in kernel function (default 3)
  143. -g gamma : set gamma in kernel function (default 1/num_features)
  144. -r coef0 : set coef0 in kernel function (default 0)
  145. -c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
  146. -n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
  147. -p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)
  148. -m cachesize : set cache memory size in MB (default 100)
  149. -e epsilon : set tolerance of termination criterion (default 0.001)
  150. -h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)
  151. -b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)
  152. -wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)
  153. -v n: n-fold cross validation mode
  154. -q : quiet mode (no outputs)
  155.  
  156. The k in the -g option means the number of attributes in the input data.
  157.  
  158. option -v randomly splits the data into n parts and calculates cross
  159. validation accuracy/mean squared error on them.
  160.  
  161. See libsvm FAQ for the meaning of outputs.
  162.  
  163. `svm-predict' Usage
  164. ===================
  165.  
  166. Usage: svm-predict [options] test_file model_file output_file
  167. options:
  168. -b probability_estimates: whether to predict probability estimates, 0 or 1 (default 0); for one-class SVM only 0 is supported
  169.  
  170. model_file is the model file generated by svm-train.
  171. test_file is the test data you want to predict.
  172. svm-predict will produce output in the output_file.
  173.  
  174. `svm-scale' Usage
  175. =================
  176.  
  177. Usage: svm-scale [options] data_filename
  178. options:
  179. -l lower : x scaling lower limit (default -1)
  180. -u upper : x scaling upper limit (default +1)
  181. -y y_lower y_upper : y scaling limits (default: no y scaling)
  182. -s save_filename : save scaling parameters to save_filename
  183. -r restore_filename : restore scaling parameters from restore_filename
  184.  
  185. See 'Examples' in this file for examples.
  186.  
  187. Tips on Practical Use
  188. =====================
  189.  
  190. * Scale your data. For example, scale each attribute to [0,1] or [-1,+1].
  191. * For C-SVC, consider using the model selection tool in the tools directory.
  192. * nu in nu-SVC/one-class-SVM/nu-SVR approximates the fraction of training
  193. errors and support vectors.
  194. * If data for classification are unbalanced (e.g. many positive and
  195. few negative), try different penalty parameters C by -wi (see
  196. examples below).
  197. * Specify larger cache size (i.e., larger -m) for huge problems.
  198.  
  199. Examples
  200. ========
  201.  
  202. > svm-scale -l -1 -u 1 -s range train > train.scale
  203. > svm-scale -r range test > test.scale
  204.  
  205. Scale each feature of the training data to be in [-1,1]. Scaling
  206. factors are stored in the file range and then used for scaling the
  207. test data.
  208.  
  209. > svm-train -s 0 -c 5 -t 2 -g 0.5 -e 0.1 data_file
  210.  
  211. Train a classifier with RBF kernel exp(-0.5|u-v|^2), C=10, and
  212. stopping tolerance 0.1.
  213.  
  214. > svm-train -s 3 -p 0.1 -t 0 data_file
  215.  
  216. Solve SVM regression with linear kernel u'v and epsilon=0.1
  217. in the loss function.
  218.  
  219. > svm-train -c 10 -w1 1 -w-2 5 -w4 2 data_file
  220.  
  221. Train a classifier with penalty 10 = 1 * 10 for class 1, penalty 50 =
  222. 5 * 10 for class -2, and penalty 20 = 2 * 10 for class 4.
  223.  
  224. > svm-train -s 0 -c 100 -g 0.1 -v 5 data_file
  225.  
  226. Do five-fold cross validation for the classifier using
  227. the parameters C = 100 and gamma = 0.1
  228.  
  229. > svm-train -s 0 -b 1 data_file
  230. > svm-predict -b 1 test_file data_file.model output_file
  231.  
  232. Obtain a model with probability information and predict test data with
  233. probability estimates
  234.  
  235. Precomputed Kernels
  236. ===================
  237.  
  238. Users may precompute kernel values and input them as training and
  239. testing files. Then libsvm does not need the original
  240. training/testing sets.
  241.  
  242. Assume there are L training instances x1, ..., xL and.
  243. Let K(x, y) be the kernel
  244. value of two instances x and y. The input formats
  245. are:
  246.  
  247. New training instance for xi:
  248.  
  249. <label> 0:i 1:K(xi,x1) ... L:K(xi,xL)
  250.  
  251. New testing instance for any x:
  252.  
  253. <label> 0:? 1:K(x,x1) ... L:K(x,xL)
  254.  
  255. That is, in the training file the first column must be the "ID" of
  256. xi. In testing, ? can be any value.
  257.  
  258. All kernel values including ZEROs must be explicitly provided. Any
  259. permutation or random subsets of the training/testing files are also
  260. valid (see examples below).
  261.  
  262. Note: the format is slightly different from the precomputed kernel
  263. package released in libsvmtools earlier.
  264.  
  265. Examples:
  266.  
  267. Assume the original training data has three four-feature
  268. instances and testing data has one instance:
  269.  
  270. 15 1:1 2:1 3:1 4:1
  271. 45 2:3 4:3
  272. 25 3:1
  273.  
  274. 15 1:1 3:1
  275.  
  276. If the linear kernel is used, we have the following new
  277. training/testing sets:
  278.  
  279. 15 0:1 1:4 2:6 3:1
  280. 45 0:2 1:6 2:18 3:0
  281. 25 0:3 1:1 2:0 3:1
  282.  
  283. 15 0:? 1:2 2:0 3:1
  284.  
  285. ? can be any value.
  286.  
  287. Any subset of the above training file is also valid. For example,
  288.  
  289. 25 0:3 1:1 2:0 3:1
  290. 45 0:2 1:6 2:18 3:0
  291.  
  292. implies that the kernel matrix is
  293.  
  294. [K(2,2) K(2,3)] = [18 0]
  295. [K(3,2) K(3,3)] = [0 1]
  296.  
  297. Library Usage
  298. =============
  299.  
  300. These functions and structures are declared in the header file
  301. `svm.h'. You need to #include "svm.h" in your C/C++ source files and
  302. link your program with `svm.cpp'. You can see `svm-train.c' and
  303. `svm-predict.c' for examples showing how to use them. We define
  304. LIBSVM_VERSION and declare `extern int libsvm_version; ' in svm.h, so
  305. you can check the version number.
  306.  
  307. Before you classify test data, you need to construct an SVM model
  308. (`svm_model') using training data. A model can also be saved in
  309. a file for later use. Once an SVM model is available, you can use it
  310. to classify new data.
  311.  
  312. - Function: struct svm_model *svm_train(const struct svm_problem *prob,
  313. const struct svm_parameter *param);
  314.  
  315. This function constructs and returns an SVM model according to
  316. the given training data and parameters.
  317.  
  318. struct svm_problem describes the problem:
  319.  
  320. struct svm_problem
  321. {
  322. int l;
  323. double *y;
  324. struct svm_node **x;
  325. };
  326.  
  327. where `l' is the number of training data, and `y' is an array containing
  328. their target values. (integers in classification, real numbers in
  329. regression) `x' is an array of pointers, each of which points to a sparse
  330. representation (array of svm_node) of one training vector.
  331.  
  332. For example, if we have the following training data:
  333.  
  334. LABEL ATTR1 ATTR2 ATTR3 ATTR4 ATTR5
  335. ----- ----- ----- ----- ----- -----
  336. 1 0 0.1 0.2 0 0
  337. 2 0 0.1 0.3 -1.2 0
  338. 1 0.4 0 0 0 0
  339. 2 0 0.1 0 1.4 0.5
  340. 3 -0.1 -0.2 0.1 1.1 0.1
  341.  
  342. then the components of svm_problem are:
  343.  
  344. l = 5
  345.  
  346. y -> 1 2 1 2 3
  347.  
  348. x -> [ ] -> (2,0.1) (3,0.2) (-1,?)
  349. [ ] -> (2,0.1) (3,0.3) (4,-1.2) (-1,?)
  350. [ ] -> (1,0.4) (-1,?)
  351. [ ] -> (2,0.1) (4,1.4) (5,0.5) (-1,?)
  352. [ ] -> (1,-0.1) (2,-0.2) (3,0.1) (4,1.1) (5,0.1) (-1,?)
  353.  
  354. where (index,value) is stored in the structure `svm_node':
  355.  
  356. struct svm_node
  357. {
  358. int index;
  359. double value;
  360. };
  361.  
  362. index = -1 indicates the end of one vector. Note that indices must
  363. be in ASCENDING order.
  364.  
  365. struct svm_parameter describes the parameters of an SVM model:
  366.  
  367. struct svm_parameter
  368. {
  369. int svm_type;
  370. int kernel_type;
  371. int degree; /* for poly */
  372. double gamma; /* for poly/rbf/sigmoid */
  373. double coef0; /* for poly/sigmoid */
  374.  
  375. /* these are for training only */
  376. double cache_size; /* in MB */
  377. double eps; /* stopping criteria */
  378. double C; /* for C_SVC, EPSILON_SVR, and NU_SVR */
  379. int nr_weight; /* for C_SVC */
  380. int *weight_label; /* for C_SVC */
  381. double* weight; /* for C_SVC */
  382. double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */
  383. double p; /* for EPSILON_SVR */
  384. int shrinking; /* use the shrinking heuristics */
  385. int probability; /* do probability estimates */
  386. };
  387.  
  388. svm_type can be one of C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR.
  389.  
  390. C_SVC: C-SVM classification
  391. NU_SVC: nu-SVM classification
  392. ONE_CLASS: one-class-SVM
  393. EPSILON_SVR: epsilon-SVM regression
  394. NU_SVR: nu-SVM regression
  395.  
  396. kernel_type can be one of LINEAR, POLY, RBF, SIGMOID.
  397.  
  398. LINEAR: u'*v
  399. POLY: (gamma*u'*v + coef0)^degree
  400. RBF: exp(-gamma*|u-v|^2)
  401. SIGMOID: tanh(gamma*u'*v + coef0)
  402. PRECOMPUTED: kernel values in training_set_file
  403.  
  404. cache_size is the size of the kernel cache, specified in megabytes.
  405. C is the cost of constraints violation.
  406. eps is the stopping criterion. (we usually use 0.00001 in nu-SVC,
  407. 0.001 in others). nu is the parameter in nu-SVM, nu-SVR, and
  408. one-class-SVM. p is the epsilon in epsilon-insensitive loss function
  409. of epsilon-SVM regression. shrinking = 1 means shrinking is conducted;
  410. = 0 otherwise. probability = 1 means model with probability
  411. information is obtained; = 0 otherwise.
  412.  
  413. nr_weight, weight_label, and weight are used to change the penalty
  414. for some classes (If the weight for a class is not changed, it is
  415. set to 1). This is useful for training classifier using unbalanced
  416. input data or with asymmetric misclassification cost.
  417.  
  418. nr_weight is the number of elements in the array weight_label and
  419. weight. Each weight[i] corresponds to weight_label[i], meaning that
  420. the penalty of class weight_label[i] is scaled by a factor of weight[i].
  421.  
  422. If you do not want to change penalty for any of the classes,
  423. just set nr_weight to 0.
  424.  
  425. *NOTE* Because svm_model contains pointers to svm_problem, you can
  426. not free the memory used by svm_problem if you are still using the
  427. svm_model produced by svm_train().
  428.  
  429. *NOTE* To avoid wrong parameters, svm_check_parameter() should be
  430. called before svm_train().
  431.  
  432. struct svm_model stores the model obtained from the training procedure.
  433. It is not recommended to directly access entries in this structure.
  434. Programmers should use the interface functions to get the values.
  435.  
  436. struct svm_model
  437. {
  438. struct svm_parameter param; /* parameter */
  439. int nr_class; /* number of classes, = 2 in regression/one class svm */
  440. int l; /* total #SV */
  441. struct svm_node **SV; /* SVs (SV[l]) */
  442. double **sv_coef; /* coefficients for SVs in decision functions (sv_coef[k-1][l]) */
  443. double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */
  444. double *probA; /* pairwise probability information */
  445. double *probB;
  446. int *sv_indices; /* sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to indicate SVs in the training set */
  447.  
  448. /* for classification only */
  449.  
  450. int *label; /* label of each class (label[k]) */
  451. int *nSV; /* number of SVs for each class (nSV[k]) */
  452. /* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
  453. /* XXX */
  454. int free_sv; /* 1 if svm_model is created by svm_load_model*/
  455. /* 0 if svm_model is created by svm_train */
  456. };
  457.  
  458. param describes the parameters used to obtain the model.
  459.  
  460. nr_class is the number of classes. It is 2 for regression and one-class SVM.
  461.  
  462. l is the number of support vectors. SV and sv_coef are support
  463. vectors and the corresponding coefficients, respectively. Assume there are
  464. k classes. For data in class j, the corresponding sv_coef includes (k-1) y*alpha vectors,
  465. where alpha's are solutions of the following two class problems:
  466. 1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k
  467. and y=1 for the first j-1 vectors, while y=-1 for the remaining k-j
  468. vectors. For example, if there are 4 classes, sv_coef and SV are like:
  469.  
  470. +-+-+-+--------------------+
  471. |1|1|1| |
  472. |v|v|v| SVs from class 1 |
  473. |2|3|4| |
  474. +-+-+-+--------------------+
  475. |1|2|2| |
  476. |v|v|v| SVs from class 2 |
  477. |2|3|4| |
  478. +-+-+-+--------------------+
  479. |1|2|3| |
  480. |v|v|v| SVs from class 3 |
  481. |3|3|4| |
  482. +-+-+-+--------------------+
  483. |1|2|3| |
  484. |v|v|v| SVs from class 4 |
  485. |4|4|4| |
  486. +-+-+-+--------------------+
  487.  
  488. See svm_train() for an example of assigning values to sv_coef.
  489.  
  490. rho is the bias term (-b). probA and probB are parameters used in
  491. probability outputs. If there are k classes, there are k*(k-1)/2
  492. binary problems as well as rho, probA, and probB values. They are
  493. aligned in the order of binary problems:
  494. 1 vs 2, 1 vs 3, ..., 1 vs k, 2 vs 3, ..., 2 vs k, ..., k-1 vs k.
  495.  
  496. sv_indices[0,...,nSV-1] are values in [1,...,num_traning_data] to
  497. indicate support vectors in the training set.
  498.  
  499. label contains labels in the training data.
  500.  
  501. nSV is the number of support vectors in each class.
  502.  
  503. free_sv is a flag used to determine whether the space of SV should
  504. be released in free_model_content(struct svm_model*) and
  505. free_and_destroy_model(struct svm_model**). If the model is
  506. generated by svm_train(), then SV points to data in svm_problem
  507. and should not be removed. For example, free_sv is 0 if svm_model
  508. is created by svm_train, but is 1 if created by svm_load_model.
  509.  
  510. - Function: double svm_predict(const struct svm_model *model,
  511. const struct svm_node *x);
  512.  
  513. This function does classification or regression on a test vector x
  514. given a model.
  515.  
  516. For a classification model, the predicted class for x is returned.
  517. For a regression model, the function value of x calculated using
  518. the model is returned. For an one-class model, +1 or -1 is
  519. returned.
  520.  
  521. - Function: void svm_cross_validation(const struct svm_problem *prob,
  522. const struct svm_parameter *param, int nr_fold, double *target);
  523.  
  524. This function conducts cross validation. Data are separated to
  525. nr_fold folds. Under given parameters, sequentially each fold is
  526. validated using the model from training the remaining. Predicted
  527. labels (of all prob's instances) in the validation process are
  528. stored in the array called target.
  529.  
  530. The format of svm_prob is same as that for svm_train().
  531.  
  532. - Function: int svm_get_svm_type(const struct svm_model *model);
  533.  
  534. This function gives svm_type of the model. Possible values of
  535. svm_type are defined in svm.h.
  536.  
  537. - Function: int svm_get_nr_class(const svm_model *model);
  538.  
  539. For a classification model, this function gives the number of
  540. classes. For a regression or an one-class model, 2 is returned.
  541.  
  542. - Function: void svm_get_labels(const svm_model *model, int* label)
  543.  
  544. For a classification model, this function outputs the name of
  545. labels into an array called label. For regression and one-class
  546. models, label is unchanged.
  547.  
  548. - Function: void svm_get_sv_indices(const struct svm_model *model, int *sv_indices)
  549.  
  550. This function outputs indices of support vectors into an array called sv_indices.
  551. The size of sv_indices is the number of support vectors and can be obtained by calling svm_get_nr_sv.
  552. Each sv_indices[i] is in the range of [1, ..., num_traning_data].
  553.  
  554. - Function: int svm_get_nr_sv(const struct svm_model *model)
  555.  
  556. This function gives the number of total support vector.
  557.  
  558. - Function: double svm_get_svr_probability(const struct svm_model *model);
  559.  
  560. For a regression model with probability information, this function
  561. outputs a value sigma > 0. For test data, we consider the
  562. probability model: target value = predicted value + z, z: Laplace
  563. distribution e^(-|z|/sigma)/(2sigma)
  564.  
  565. If the model is not for svr or does not contain required
  566. information, 0 is returned.
  567.  
  568. - Function: double svm_predict_values(const svm_model *model,
  569. const svm_node *x, double* dec_values)
  570.  
  571. This function gives decision values on a test vector x given a
  572. model, and return the predicted label (classification) or
  573. the function value (regression).
  574.  
  575. For a classification model with nr_class classes, this function
  576. gives nr_class*(nr_class-1)/2 decision values in the array
  577. dec_values, where nr_class can be obtained from the function
  578. svm_get_nr_class. The order is label[0] vs. label[1], ...,
  579. label[0] vs. label[nr_class-1], label[1] vs. label[2], ...,
  580. label[nr_class-2] vs. label[nr_class-1], where label can be
  581. obtained from the function svm_get_labels. The returned value is
  582. the predicted class for x. Note that when nr_class = 1, this
  583. function does not give any decision value.
  584.  
  585. For a regression model, dec_values[0] and the returned value are
  586. both the function value of x calculated using the model. For a
  587. one-class model, dec_values[0] is the decision value of x, while
  588. the returned value is +1/-1.
  589.  
  590. - Function: double svm_predict_probability(const struct svm_model *model,
  591. const struct svm_node *x, double* prob_estimates);
  592.  
  593. This function does classification or regression on a test vector x
  594. given a model with probability information.
  595.  
  596. For a classification model with probability information, this
  597. function gives nr_class probability estimates in the array
  598. prob_estimates. nr_class can be obtained from the function
  599. svm_get_nr_class. The class with the highest probability is
  600. returned. For regression/one-class SVM, the array prob_estimates
  601. is unchanged and the returned value is the same as that of
  602. svm_predict.
  603.  
  604. - Function: const char *svm_check_parameter(const struct svm_problem *prob,
  605. const struct svm_parameter *param);
  606.  
  607. This function checks whether the parameters are within the feasible
  608. range of the problem. This function should be called before calling
  609. svm_train() and svm_cross_validation(). It returns NULL if the
  610. parameters are feasible, otherwise an error message is returned.
  611.  
  612. - Function: int svm_check_probability_model(const struct svm_model *model);
  613.  
  614. This function checks whether the model contains required
  615. information to do probability estimates. If so, it returns
  616. +1. Otherwise, 0 is returned. This function should be called
  617. before calling svm_get_svr_probability and
  618. svm_predict_probability.
  619.  
  620. - Function: int svm_save_model(const char *model_file_name,
  621. const struct svm_model *model);
  622.  
  623. This function saves a model to a file; returns 0 on success, or -1
  624. if an error occurs.
  625.  
  626. - Function: struct svm_model *svm_load_model(const char *model_file_name);
  627.  
  628. This function returns a pointer to the model read from the file,
  629. or a null pointer if the model could not be loaded.
  630.  
  631. - Function: void svm_free_model_content(struct svm_model *model_ptr);
  632.  
  633. This function frees the memory used by the entries in a model structure.
  634.  
  635. - Function: void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr);
  636.  
  637. This function frees the memory used by a model and destroys the model
  638. structure. It is equivalent to svm_destroy_model, which
  639. is deprecated after version 3.0.
  640.  
  641. - Function: void svm_destroy_param(struct svm_parameter *param);
  642.  
  643. This function frees the memory used by a parameter set.
  644.  
  645. - Function: void svm_set_print_string_function(void (*print_func)(const char *));
  646.  
  647. Users can specify their output format by a function. Use
  648. svm_set_print_string_function(NULL);
  649. for default printing to stdout.
  650.  
  651. Java Version
  652. ============
  653.  
  654. The pre-compiled java class archive `libsvm.jar' and its source files are
  655. in the java directory. To run the programs, use
  656.  
  657. java -classpath libsvm.jar svm_train <arguments>
  658. java -classpath libsvm.jar svm_predict <arguments>
  659. java -classpath libsvm.jar svm_toy
  660. java -classpath libsvm.jar svm_scale <arguments>
  661.  
  662. Note that you need Java 1.5 (5.0) or above to run it.
  663.  
  664. You may need to add Java runtime library (like classes.zip) to the classpath.
  665. You may need to increase maximum Java heap size.
  666.  
  667. Library usages are similar to the C version. These functions are available:
  668.  
  669. public class svm {
  670. public static final int LIBSVM_VERSION=318;
  671. public static svm_model svm_train(svm_problem prob, svm_parameter param);
  672. public static void svm_cross_validation(svm_problem prob, svm_parameter param, int nr_fold, double[] target);
  673. public static int svm_get_svm_type(svm_model model);
  674. public static int svm_get_nr_class(svm_model model);
  675. public static void svm_get_labels(svm_model model, int[] label);
  676. public static void svm_get_sv_indices(svm_model model, int[] indices);
  677. public static int svm_get_nr_sv(svm_model model);
  678. public static double svm_get_svr_probability(svm_model model);
  679. public static double svm_predict_values(svm_model model, svm_node[] x, double[] dec_values);
  680. public static double svm_predict(svm_model model, svm_node[] x);
  681. public static double svm_predict_probability(svm_model model, svm_node[] x, double[] prob_estimates);
  682. public static void svm_save_model(String model_file_name, svm_model model) throws IOException
  683. public static svm_model svm_load_model(String model_file_name) throws IOException
  684. public static String svm_check_parameter(svm_problem prob, svm_parameter param);
  685. public static int svm_check_probability_model(svm_model model);
  686. public static void svm_set_print_string_function(svm_print_interface print_func);
  687. }
  688.  
  689. The library is in the "libsvm" package.
  690. Note that in Java version, svm_node[] is not ended with a node whose index = -1.
  691.  
  692. Users can specify their output format by
  693.  
  694. your_print_func = new svm_print_interface()
  695. {
  696. public void print(String s)
  697. {
  698. // your own format
  699. }
  700. };
  701. svm.svm_set_print_string_function(your_print_func);
  702.  
  703. Building Windows Binaries
  704. =========================
  705.  
  706. Windows binaries are in the directory `windows'. To build them via
  707. Visual C++, use the following steps:
  708.  
  709. 1. Open a DOS command box (or Visual Studio Command Prompt) and change
  710. to libsvm directory. If environment variables of VC++ have not been
  711. set, type
  712.  
  713. "C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
  714.  
  715. You may have to modify the above command according which version of
  716. VC++ or where it is installed.
  717.  
  718. 2. Type
  719.  
  720. nmake -f Makefile.win clean all
  721.  
  722. 3. (optional) To build shared library libsvm.dll, type
  723.  
  724. nmake -f Makefile.win lib
  725.  
  726. 4. (optional) To build 64-bit windows binaries, you must
  727. (1) Setup vcvars64.bat instead of vcvars32.bat
  728. (2) Change CFLAGS in Makefile.win: /D _WIN32 to /D _WIN64
  729.  
  730. Another way is to build them from Visual C++ environment. See details
  731. in libsvm FAQ.
  732.  
  733. - Additional Tools: Sub-sampling, Parameter Selection, Format checking, etc.
  734. ============================================================================
  735.  
  736. See the README file in the tools directory.
  737.  
  738. MATLAB/OCTAVE Interface
  739. =======================
  740.  
  741. Please check the file README in the directory `matlab'.
  742.  
  743. Python Interface
  744. ================
  745.  
  746. See the README file in python directory.
  747.  
  748. Additional Information
  749. ======================
  750.  
  751. If you find LIBSVM helpful, please cite it as
  752.  
  753. Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for support
  754. vector machines. ACM Transactions on Intelligent Systems and
  755. Technology, 2:27:1--27:27, 2011. Software available at
  756. http://www.csie.ntu.edu.tw/~cjlin/libsvm
  757.  
  758. LIBSVM implementation document is available at
  759. http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf
  760.  
  761. For any questions and comments, please email cjlin@csie.ntu.edu.tw
  762.  
  763. Acknowledgments:
  764. This work was supported in part by the National Science
  765. Council of Taiwan via the grant NSC 89-2213-E-002-013.
  766. The authors thank their group members and users
  767. for many helpful discussions and comments. They are listed in
  768. http://www.csie.ntu.edu.tw/~cjlin/libsvm/acknowledgements

libsvm_readme[zz from github]的更多相关文章

  1. 搜刮一些开源项目的APP

    iOS完整App资源收集 <iOS完整app资源收集>  <GitHub 上有哪些完整的 iOS-App 源码值得参考?> <GitHub 上有哪些完整的 iOS-App ...

  2. git/github初级运用自如(zz)

    ----//git/github环境配置 一 .  github上创建立一个项目 用户登录后系统,在github首页,点击页面右下角“New Repository” 填写项目信息: project n ...

  3. zz github配置

    First : 安装:ubuntu 下,终端输入命令: sudo apt-get install git-core git-gui git-doc Next : 设置SSH Key 检查是否已经有SS ...

  4. 【ZZ】号称“开发者神器”的GitHub,到底该怎么用?

    号称“开发者神器”的GitHub,到底该怎么用? https://mp.weixin.qq.com/s/zpKOBMKWckY05Mv_B28RgQ A developer’s introductio ...

  5. Git/Github的使用并与Eclipse整合(zz)

    Git/Github的使用并与Eclipse整合 您的评价:          收藏该经验       Git简介 Git是一个免费的.分布式的版本控制工具,或是一个强调了速度快的源代码管理工具.每一 ...

  6. 从github下载某个git库的4种方法[zz]

    以gerrit-trigger-plugin为例,下面的链接都是从相应页面上直接拷贝的. 法一:不用github的账号,打开这个库在github上的主页,运行下面命令即可 read only 运行命令 ...

  7. 关于如何使用sourcetree将本地项目提交到远端github总结?

    使用sourcetree将本地项目提交到github里,目前来说还是很流行的,我也是听说好玩,所以来琢磨了一下,从环境搭建到配置好,差不多用了一下午加一晚上的时间,有点虐心,好吧,废话不多说,介绍一下 ...

  8. 使用git向github中添加项目并更新(备忘录)

    今天使用Git&github&ST3时,发现ST3不仅是git插件不能push成功,使用sublimegit插件也不行. 可能是没有掌握sublimegit的使用技巧,有待后续继续摸索 ...

  9. GitHub 里面有大量优秀的第三方框架

    写iOS 程序的时候往往需要很多第三方框架的支持,可以大大减少工作量,讲重点放在软件本身的逻辑实现上. GitHub 里面有大量优秀的第三方框架,而且 License 对商业很友好.一下摘录一下几乎每 ...

随机推荐

  1. SQL Server中float转字符串进度丢失

    写了个函数接受varchar的参数, 但实际传入的是float, 但是转换后舍入成2位小数了, 单独执行没问题, 从table中查询输出就有问题 REF SELECT CAST(CAST(字段 AS ...

  2. jconsole监控远程linux tomcat运行情况的配置 (转)

    来自:http://zhumeng8337797.blog.163.com/blog/static/100768914201242494649455/ 步骤如下: 1.编辑tomcat/bin/cat ...

  3. Pig jline.Terminal错误

    运行Pig时出现这个错误: [main] ERROR org.apache.pig.Main - ERROR 2998: Unhandled internal error. Found interfa ...

  4. 算法笔记_232:提取拼音首字母(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 在很多软件中,输入拼音的首写字母就可以快速定位到某个词条.比如,在铁路售票软件中,输入: “bj”就可以定位到“北京”.怎样在自己的软件中实现这个功 ...

  5. 安装了XAMPP,PHP怎么显示中文

    1.输出前加文件头.header("Content-type: text/html; charset=utf-8"); 另外注意你的文件编码要和 charset一致. 2. 可能是 ...

  6. Struts2+JSON数据

    待整理 参考 http://yshjava.iteye.com/blog/1333104 http://kingxss.iteye.com/blog/1622455 JSON中,java.lang.N ...

  7. rac安装_grid安装校验报错之grid未建立信任关系

    原创作品,出自 "深蓝的blog" 博客,欢迎转载,转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...

  8. ios中地图

    参考文章  http://blog.csdn.net/tangaowen/article/details/6527901 http://www.cnblogs.com/tangbinblog/arch ...

  9. ios中非ARC项目中引用ARC文件

    下图即可 选中工程->TARGETS->相应的target然后选中右侧的“Build Phases”,向下就找到“Compile Sources”了.如何在未使用arc的工程中引入一个使用 ...

  10. Swift中的Any 与 AnyObject、AnyClass的区别?

    在 Swift 中能够表示 “任意” 这个概念的除了Any .AnyObject以外,还有一个AnyClass. Any.AnyObject.AnyClass有什么区别: AnyObject是一个成员 ...