eluka 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.document +5 -0
  2. data/DOCUMENTATION_STANDARDS +39 -0
  3. data/Gemfile +13 -0
  4. data/Gemfile.lock +20 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +69 -0
  8. data/VERSION +1 -0
  9. data/examples/example.rb +59 -0
  10. data/ext/libsvm/COPYRIGHT +31 -0
  11. data/ext/libsvm/FAQ.html +1749 -0
  12. data/ext/libsvm/Makefile +25 -0
  13. data/ext/libsvm/Makefile.win +33 -0
  14. data/ext/libsvm/README +733 -0
  15. data/ext/libsvm/extconf.rb +1 -0
  16. data/ext/libsvm/heart_scale +270 -0
  17. data/ext/libsvm/java/Makefile +25 -0
  18. data/ext/libsvm/java/libsvm.jar +0 -0
  19. data/ext/libsvm/java/libsvm/svm.java +2776 -0
  20. data/ext/libsvm/java/libsvm/svm.m4 +2776 -0
  21. data/ext/libsvm/java/libsvm/svm_model.java +21 -0
  22. data/ext/libsvm/java/libsvm/svm_node.java +6 -0
  23. data/ext/libsvm/java/libsvm/svm_parameter.java +47 -0
  24. data/ext/libsvm/java/libsvm/svm_print_interface.java +5 -0
  25. data/ext/libsvm/java/libsvm/svm_problem.java +7 -0
  26. data/ext/libsvm/java/svm_predict.java +163 -0
  27. data/ext/libsvm/java/svm_scale.java +350 -0
  28. data/ext/libsvm/java/svm_toy.java +471 -0
  29. data/ext/libsvm/java/svm_train.java +318 -0
  30. data/ext/libsvm/java/test_applet.html +1 -0
  31. data/ext/libsvm/python/Makefile +4 -0
  32. data/ext/libsvm/python/README +331 -0
  33. data/ext/libsvm/python/svm.py +259 -0
  34. data/ext/libsvm/python/svmutil.py +242 -0
  35. data/ext/libsvm/svm-predict.c +226 -0
  36. data/ext/libsvm/svm-scale.c +353 -0
  37. data/ext/libsvm/svm-toy/gtk/Makefile +22 -0
  38. data/ext/libsvm/svm-toy/gtk/callbacks.cpp +423 -0
  39. data/ext/libsvm/svm-toy/gtk/callbacks.h +54 -0
  40. data/ext/libsvm/svm-toy/gtk/interface.c +164 -0
  41. data/ext/libsvm/svm-toy/gtk/interface.h +14 -0
  42. data/ext/libsvm/svm-toy/gtk/main.c +23 -0
  43. data/ext/libsvm/svm-toy/gtk/svm-toy.glade +238 -0
  44. data/ext/libsvm/svm-toy/qt/Makefile +17 -0
  45. data/ext/libsvm/svm-toy/qt/svm-toy.cpp +413 -0
  46. data/ext/libsvm/svm-toy/windows/svm-toy.cpp +456 -0
  47. data/ext/libsvm/svm-train.c +376 -0
  48. data/ext/libsvm/svm.cpp +3060 -0
  49. data/ext/libsvm/svm.def +19 -0
  50. data/ext/libsvm/svm.h +105 -0
  51. data/ext/libsvm/svm.o +0 -0
  52. data/ext/libsvm/tools/README +149 -0
  53. data/ext/libsvm/tools/checkdata.py +108 -0
  54. data/ext/libsvm/tools/easy.py +79 -0
  55. data/ext/libsvm/tools/grid.py +359 -0
  56. data/ext/libsvm/tools/subset.py +146 -0
  57. data/ext/libsvm/windows/libsvm.dll +0 -0
  58. data/ext/libsvm/windows/svm-predict.exe +0 -0
  59. data/ext/libsvm/windows/svm-scale.exe +0 -0
  60. data/ext/libsvm/windows/svm-toy.exe +0 -0
  61. data/ext/libsvm/windows/svm-train.exe +0 -0
  62. data/lib/eluka.rb +10 -0
  63. data/lib/eluka/bijection.rb +23 -0
  64. data/lib/eluka/data_point.rb +36 -0
  65. data/lib/eluka/document.rb +47 -0
  66. data/lib/eluka/feature_vector.rb +86 -0
  67. data/lib/eluka/features.rb +31 -0
  68. data/lib/eluka/model.rb +129 -0
  69. data/lib/fselect.rb +321 -0
  70. data/lib/grid.rb +25 -0
  71. data/test/helper.rb +18 -0
  72. data/test/test_eluka.rb +7 -0
  73. metadata +214 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,39 @@
1
+ Got this document from Merb via Ferret:
2
+
3
+ # Render the specified item, with the specified options.
4
+ #
5
+ # ==== Parameters
6
+ # thing<String, Symbol, nil>::
7
+ # The thing to render. This will default to the current action
8
+ # opts<Hash>:: An options hash (see below)
9
+ #
10
+ # ==== Options (opts)
11
+ # :format<Symbol>:: A registered mime-type format
12
+ # :template<String>::
13
+ # The path to the template relative to the template root
14
+ # :status<~to_i>::
15
+ # The status to send to the client. Typically, this would
16
+ # be an integer (200), or a Merb status code (Accepted)
17
+ # :layout<~to_s>::
18
+ # A layout to use instead of the default. This should be
19
+ # relative to the layout root. By default, the layout will
20
+ # be either the controller_name or application. If you
21
+ # want to use an alternative content-type than the one
22
+ # that the base template was rendered as, you will need
23
+ # to do :layout => +foo.#{content_type}+ (i.e. +foo.json+)
24
+ #
25
+ # ==== Returns
26
+ # String:: The rendered template, including layout, if appropriate.
27
+ #
28
+ # ==== Raises
29
+ # TemplateNotFound::
30
+ # There is no template for the specified location.
31
+ #
32
+ # ==== Alternatives
33
+ # If you pass a Hash as the first parameter, it will be moved to
34
+ # opts and +thing+ will be the current action
35
+ #
36
+ # @public
37
+ def render(thing = nil, opts = {})
38
+ <snip>
39
+ end
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.1"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.1)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.5.1)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Aditya Rachakonda
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = eluka
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to eluka
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Aditya Rachakonda. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,69 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'rake'
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "eluka"
17
+ gem.homepage = "http://github.com/arrac/eluka"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{one-line summary of your gem}
20
+ gem.description = %Q{longer description of your gem}
21
+ gem.email = "aditya.rachakonda@gmail.com"
22
+ gem.authors = ["Aditya Rachakonda"]
23
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
24
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
25
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
27
+
28
+ gem.add_dependency 'ferret'
29
+ gem.extensions.push 'ext/libsvm'
30
+ end
31
+
32
+ Jeweler::RubygemsDotOrgTasks.new
33
+
34
+ require 'rake/testtask'
35
+ Rake::TestTask.new(:test) do |test|
36
+ test.libs << 'lib' << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ end
40
+
41
+ require 'rcov/rcovtask'
42
+ Rcov::RcovTask.new do |test|
43
+ test.libs << 'test'
44
+ test.pattern = 'test/**/test_*.rb'
45
+ test.verbose = true
46
+ end
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "eluka #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
59
+
60
+ # task :install do
61
+ # puts "Install"
62
+ # `touch /tmp/12345install`
63
+ # end
64
+ #
65
+ # task :build do
66
+ # puts "Build"
67
+ # `touch /tmp/12345build`
68
+ # end
69
+ #
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,59 @@
1
+ #$LOAD_PATH.push('./')
2
+ require 'rubygems'
3
+ require 'eluka'
4
+ require 'pp'
5
+
6
+ model = Eluka::Model.new(:directory => '/Users/raditya/Desktop',
7
+ # :svm_train_path => "/opt/local/bin/svm-train",
8
+ # :svm_scale_path => "/opt/local/bin/svm-scale",
9
+ # :svm_predict_path => "/opt/local/bin/svm-predict",
10
+ :grid_py_path => "python /Users/raditya/Dropbox/Yahoo Internship/Code/libsvm-3.0/tools/grid.py",
11
+ :fselect_py_path => "python /Users/raditya/Dropbox/Yahoo Internship/Code/libsvm-3.0/tools/fselect.py")
12
+
13
+ d1 = {:x => 3, :y => 1}
14
+ d2 = {:x => 1, :y => 3}
15
+ d3 = {:x => 3.5, :y => 1}
16
+ d4 = {:x => 1, :y => 4, :text => "Japanese Chinese", :title => "Cool great"}
17
+ d5 = {:x => 0, :y => 5}
18
+
19
+ model.add(d1, :positive)
20
+ model.add(d2, :negative)
21
+ model.add(d3, :positive)
22
+ model.add(d4, :negative)
23
+ model.add("Chinese Japanese", :positive)
24
+ model.add("Chinese Japanese", :positive)
25
+ model.add("Chinese Japanese", :positive)
26
+ model.add("Chinese Japanese", :positive)
27
+ model.add("Chinese Japanese", :positive)
28
+ model.build
29
+
30
+ #pp model.suggest_features
31
+
32
+ puts model.classify(d5)
33
+
34
+ __END__
35
+ model.add("Chinese Beijing Chinese", :positive)
36
+ model.add("Chinese Chinese Shanghai", :positive)
37
+ model.add("Chinese Macao", :positive)
38
+ model.add("Tokyo Japan Chinese", :negative)
39
+ #model.add("Tokyo Japan Chinese", :negative)
40
+ #model.add("Tokyo Japan Chinese", :negative)
41
+
42
+ features = model.suggest_features
43
+
44
+ features.push("beijing")
45
+ #pp features
46
+
47
+ model.build(features)
48
+
49
+ puts model.classify("Chinese Chinese Chinese Beijing Tokyo Japan India")
50
+
51
+
52
+ __END__
53
+
54
+ #(:verbose => true)#(:directory => "/Users/raditya/Desktop")#,
55
+ # :svm_train_path => "/opt/local/bin/svm-train",
56
+ # :svm_scale_path => "/opt/local/bin/svm-scale",
57
+ # :svm_predict_path => "/opt/local/bin/svm-predict",
58
+ # :grid_py_path => "python /Users/raditya/Dropbox/Yahoo Internship/Code/libsvm-3.0/tools/grid.py",
59
+ # :fselect_py_path => "python /Users/raditya/Dropbox/Yahoo Internship/Code/libsvm-3.0/tools/fselect.py")
@@ -0,0 +1,31 @@
1
+
2
+ Copyright (c) 2000-2010 Chih-Chung Chang and Chih-Jen Lin
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions
7
+ are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+
16
+ 3. Neither name of copyright holders nor the names of its contributors
17
+ may be used to endorse or promote products derived from this software
18
+ without specific prior written permission.
19
+
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
25
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,1749 @@
1
+ <html>
2
+ <head>
3
+ <title>LIBSVM FAQ</title>
4
+ </head>
5
+ <body bgcolor="#ffffcc">
6
+
7
+ <a name="_TOP"><b><h1><a
8
+ href=http://www.csie.ntu.edu.tw/~cjlin/libsvm>LIBSVM</a> FAQ </h1></b></a>
9
+ <b>last modified : </b>
10
+ Mon, 29 Mar 2010 12:08:25 GMT
11
+ <class="categories">
12
+ <li><a
13
+ href="#_TOP">All Questions</a>(76)</li>
14
+ <ul><b>
15
+ <li><a
16
+ href="#/Q1:_Some_sample_uses_of_libsvm">Q1:_Some_sample_uses_of_libsvm</a>(2)</li>
17
+ <li><a
18
+ href="#/Q2:_Installation_and_running_the_program">Q2:_Installation_and_running_the_program</a>(10)</li>
19
+ <li><a
20
+ href="#/Q3:_Data_preparation">Q3:_Data_preparation</a>(7)</li>
21
+ <li><a
22
+ href="#/Q4:_Training_and_prediction">Q4:_Training_and_prediction</a>(33)</li>
23
+ <li><a
24
+ href="#/Q5:_Probability_outputs">Q5:_Probability_outputs</a>(3)</li>
25
+ <li><a
26
+ href="#/Q6:_Graphic_interface">Q6:_Graphic_interface</a>(3)</li>
27
+ <li><a
28
+ href="#/Q7:_Java_version_of_libsvm">Q7:_Java_version_of_libsvm</a>(4)</li>
29
+ <li><a
30
+ href="#/Q8:_Python_interface">Q8:_Python_interface</a>(5)</li>
31
+ <li><a
32
+ href="#/Q9:_MATLAB_interface">Q9:_MATLAB_interface</a>(9)</li>
33
+ </b></ul>
34
+ </li>
35
+
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 which have used libsvm </a></li>
39
+ <li class="headlines_item"><a href="#f201">Where can I find documents 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">I would like to cite LIBSVM. Which paper should I cite? </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="#f301">Why sometimes not all attributes of a data appear in the training/model files ?</a></li>
50
+ <li class="headlines_item"><a href="#f302">What if my data are non-numerical ?</a></li>
51
+ <li class="headlines_item"><a href="#f303">Why do you consider sparse format ? Will the training of dense data be much slower ?</a></li>
52
+ <li class="headlines_item"><a href="#f304">Why sometimes the last line of my data is not read by svm-train?</a></li>
53
+ <li class="headlines_item"><a href="#f305">Is there a program to check if my data are in the correct format?</a></li>
54
+ <li class="headlines_item"><a href="#f306">May I put comments in data files?</a></li>
55
+ <li class="headlines_item"><a href="#f307">How to convert other data formats to LIBSVM format?</a></li>
56
+ <li class="headlines_item"><a href="#f401">The output of training C-SVM is like the following. What do they mean?</a></li>
57
+ <li class="headlines_item"><a href="#f402">Can you explain more about the model file?</a></li>
58
+ <li class="headlines_item"><a href="#f403">Should I use float or double to store numbers in the cache ?</a></li>
59
+ <li class="headlines_item"><a href="#f404">How do I choose the kernel?</a></li>
60
+ <li class="headlines_item"><a href="#f405">Does libsvm have special treatments for linear SVM?</a></li>
61
+ <li class="headlines_item"><a href="#f406">The number of free support vectors is large. What should I do?</a></li>
62
+ <li class="headlines_item"><a href="#f407">Should I scale training and testing data in a similar way?</a></li>
63
+ <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>
64
+ <li class="headlines_item"><a href="#f409">The prediction rate is low. How could I improve it?</a></li>
65
+ <li class="headlines_item"><a href="#f410">My data are unbalanced. Could libsvm handle such problems?</a></li>
66
+ <li class="headlines_item"><a href="#f411">What is the difference between nu-SVC and C-SVC?</a></li>
67
+ <li class="headlines_item"><a href="#f412">The program keeps running (without showing any output). What should I do?</a></li>
68
+ <li class="headlines_item"><a href="#f413">The program keeps running (with output, i.e. many dots). What should I do?</a></li>
69
+ <li class="headlines_item"><a href="#f414">The training time is too long. What should I do?</a></li>
70
+ <li class="headlines_item"><a href="#f4141">Does shrinking always help?</a></li>
71
+ <li class="headlines_item"><a href="#f415">How do I get the decision value(s)?</a></li>
72
+ <li class="headlines_item"><a href="#f4151">How do I get the distance between a point and the hyperplane?</a></li>
73
+ <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>
74
+ <li class="headlines_item"><a href="#f417">How do I disable screen output of svm-train and svm-predict ?</a></li>
75
+ <li class="headlines_item"><a href="#f418">I would like to use my own kernel but find out that there are two subroutines for kernel evaluations: k_function() and kernel_function(). Which one should I modify ?</a></li>
76
+ <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>
77
+ <li class="headlines_item"><a href="#f420">After doing cross validation, why there is no model file outputted ?</a></li>
78
+ <li class="headlines_item"><a href="#f4201">Why my cross-validation results are different from those in the Practical Guide?</a></li>
79
+ <li class="headlines_item"><a href="#f421">But on some systems CV accuracy is the same in several runs. How could I use different data partitions?</a></li>
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="#f424">How do I choose parameters for one-class svm as training data are in only one class?</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="#f428">Why on windows sometimes grid.py fails?</a></li>
84
+ <li class="headlines_item"><a href="#f429">Why grid.py/easy.py sometimes generates the following warning message?</a></li>
85
+ <li class="headlines_item"><a href="#f430">Why the sign of predicted labels and decision values are sometimes reversed?</a></li>
86
+ <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>
87
+ <li class="headlines_item"><a href="#f432">How can I use OpenMP to parallelize LIBSVM on a multicore/shared-memory computer?</a></li>
88
+ <li class="headlines_item"><a href="#f433">How could I know which training instances are support vectors?</a></li>
89
+ <li class="headlines_item"><a href="#f425">Why training a probability model (i.e., -b 1) takes a longer time?</a></li>
90
+ <li class="headlines_item"><a href="#f426">Why using the -b option does not give me better accuracy?</a></li>
91
+ <li class="headlines_item"><a href="#f427">Why using svm-predict -b 0 and -b 1 gives different accuracy values?</a></li>
92
+ <li class="headlines_item"><a href="#f501">How can I save images drawn by svm-toy?</a></li>
93
+ <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>
94
+ <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>
95
+ <li class="headlines_item"><a href="#f601">What is the difference between Java version and C++ version of libsvm?</a></li>
96
+ <li class="headlines_item"><a href="#f602">Is the Java version significantly slower than the C++ version?</a></li>
97
+ <li class="headlines_item"><a href="#f603">While training I get the following error message: java.lang.OutOfMemoryError. What is wrong?</a></li>
98
+ <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>
99
+ <li class="headlines_item"><a href="#f702">On MS windows, why does python fail to load the pyd file?</a></li>
100
+ <li class="headlines_item"><a href="#f703">How to modify the python interface on MS windows and rebuild the .pyd file ?</a></li>
101
+ <li class="headlines_item"><a href="#f704">Except the python-C++ interface provided, could I use Jython to call libsvm ?</a></li>
102
+ <li class="headlines_item"><a href="#f705">How could I install the python interface on Mac OS? </a></li>
103
+ <li class="headlines_item"><a href="#f706">I typed "make" on a unix system, but it says "Python.h: No such file or directory?"</a></li>
104
+ <li class="headlines_item"><a href="#f801">I compile the MATLAB interface without problem, but why errors occur while running it?</a></li>
105
+ <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>
106
+ <li class="headlines_item"><a href="#f802">Does the MATLAB interface provide a function to do scaling?</a></li>
107
+ <li class="headlines_item"><a href="#f803">How could I use MATLAB interface for parameter selection?</a></li>
108
+ <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>
109
+ <li class="headlines_item"><a href="#f8032">How do I use LIBSVM with OpenMP under MATLAB?</a></li>
110
+ <li class="headlines_item"><a href="#f804">How could I generate the primal variable w of linear SVM?</a></li>
111
+ <li class="headlines_item"><a href="#f805">Is there an OCTAVE interface for libsvm?</a></li>
112
+ <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>
113
+ </ul></ul>
114
+
115
+
116
+ <hr size="5" noshade />
117
+ <p/>
118
+
119
+ <a name="/Q1:_Some_sample_uses_of_libsvm"></a>
120
+ <a name="faq101"><b>Q: Some courses which have used libsvm as a tool</b></a>
121
+ <br/>
122
+ <ul>
123
+ <li><a href=http://lmb.informatik.uni-freiburg.de/lectures/svm_seminar/>Institute for Computer Science,
124
+ Faculty of Applied Science, University of Freiburg, Germany
125
+ </a>
126
+ <li> <a href=http://www.cs.vu.nl/~elena/ml.html>
127
+ Division of Mathematics and Computer Science.
128
+ Faculteit der Exacte Wetenschappen
129
+ Vrije Universiteit, The Netherlands. </a>
130
+ <li>
131
+ <a href=http://www.cae.wisc.edu/~ece539/matlab/>
132
+ Electrical and Computer Engineering Department,
133
+ University of Wisconsin-Madison
134
+ </a>
135
+ <li>
136
+ <a href=http://www.hpl.hp.com/personal/Carl_Staelin/cs236601/project.html>
137
+ Technion (Israel Institute of Technology), Israel.
138
+ <li>
139
+ <a href=http://www.cise.ufl.edu/~fu/learn.html>
140
+ Computer and Information Sciences Dept., University of Florida</a>
141
+ <li>
142
+ <a href=http://www.uonbi.ac.ke/acad_depts/ics/course_material/machine_learning/ML_and_DM_Resources.html>
143
+ The Institute of Computer Science,
144
+ University of Nairobi, Kenya.</a>
145
+ <li>
146
+ <a href=http://cerium.raunvis.hi.is/~tpr/courseware/svm/hugbunadur.html>
147
+ Applied Mathematics and Computer Science, University of Iceland.
148
+ <li>
149
+ <a href=http://chicago05.mlss.cc/tiki/tiki-read_article.php?articleId=2>
150
+ SVM tutorial in machine learning
151
+ summer school, University of Chicago, 2005.
152
+ </a>
153
+ </ul>
154
+ <p align="right">
155
+ <a href="#_TOP">[Go Top]</a>
156
+ <hr/>
157
+ <a name="/Q1:_Some_sample_uses_of_libsvm"></a>
158
+ <a name="faq102"><b>Q: Some applications which have used libsvm </b></a>
159
+ <br/>
160
+ <ul>
161
+ <li>
162
+ <a href=http://people.csail.mit.edu/jjl/libpmk/>LIBPMK: A Pyramid Match Toolkit</a>
163
+ </li>
164
+ <li><a href=http://maltparser.org/>Maltparser</a>:
165
+ a system for data-driven dependency parsing
166
+ </li>
167
+ <li>
168
+ <a href=http://www.pymvpa.org/>PyMVPA: python tool for classifying neuroimages</a>
169
+ </li>
170
+ <li>
171
+ <a href=http://solpro.proteomics.ics.uci.edu/>
172
+ SOLpro: protein solubility predictor
173
+ </a>
174
+ </li>
175
+ <li>
176
+ <a href=http://icb.med.cornell.edu/wiki/index.php/BDVAL>
177
+ BDVAL</a>: biomarker discovery in high-throughput datasets.
178
+ </li>
179
+ <li><a href=http://johel.m.free.fr/demo_045.htm>
180
+ Realtime object recognition</a>
181
+ </li>
182
+ </ul>
183
+ <p align="right">
184
+ <a href="#_TOP">[Go Top]</a>
185
+ <hr/>
186
+ <a name="/Q2:_Installation_and_running_the_program"></a>
187
+ <a name="f201"><b>Q: Where can I find documents of libsvm ?</b></a>
188
+ <br/>
189
+ <p>
190
+ In the package there is a README file which
191
+ details all options, data format, and library calls.
192
+ The model selection tool and the python interface
193
+ have a separate README under the directory python.
194
+ The guide
195
+ <A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf">
196
+ A practical guide to support vector classification
197
+ </A> shows beginners how to train/test their data.
198
+ The paper <a href="http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf">LIBSVM
199
+ : a library for support vector machines</a> discusses the implementation of
200
+ libsvm in detail.
201
+ <p align="right">
202
+ <a href="#_TOP">[Go Top]</a>
203
+ <hr/>
204
+ <a name="/Q2:_Installation_and_running_the_program"></a>
205
+ <a name="f202"><b>Q: Where are change log and earlier versions?</b></a>
206
+ <br/>
207
+ <p>See <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/log">the change log</a>.
208
+
209
+ <p> You can download earlier versions
210
+ <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/oldfiles">here</a>.
211
+ <p align="right">
212
+ <a href="#_TOP">[Go Top]</a>
213
+ <hr/>
214
+ <a name="/Q2:_Installation_and_running_the_program"></a>
215
+ <a name="f203"><b>Q: I would like to cite LIBSVM. Which paper should I cite? </b></a>
216
+ <br/>
217
+ <p>
218
+ Please cite the following document:
219
+ <p>
220
+ Chih-Chung Chang and Chih-Jen Lin, LIBSVM
221
+ : a library for support vector machines, 2001.
222
+ Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm
223
+ <p>
224
+ The bibtex format is
225
+ <pre>
226
+ @Manual{CC01a,
227
+ author = {Chih-Chung Chang and Chih-Jen Lin},
228
+ title = {{LIBSVM}: a library for support vector machines},
229
+ year = {2001},
230
+ note = {Software available at \url{http://www.csie.ntu.edu.tw/~cjlin/libsvm}}
231
+ }
232
+ </pre>
233
+ <p align="right">
234
+ <a href="#_TOP">[Go Top]</a>
235
+ <hr/>
236
+ <a name="/Q2:_Installation_and_running_the_program"></a>
237
+ <a name="f204"><b>Q: I would like to use libsvm in my software. Is there any license problem?</b></a>
238
+ <br/>
239
+ <p>
240
+ The libsvm license ("the modified BSD license")
241
+ is compatible with many
242
+ free software licenses such as GPL. Hence, it is very easy to
243
+ use libsvm in your software.
244
+ It can also be used in commercial products.
245
+ <p align="right">
246
+ <a href="#_TOP">[Go Top]</a>
247
+ <hr/>
248
+ <a name="/Q2:_Installation_and_running_the_program"></a>
249
+ <a name="f205"><b>Q: Is there a repository of additional tools based on libsvm?</b></a>
250
+ <br/>
251
+ <p>
252
+ Yes, see <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvmtools">libsvm
253
+ tools</a>
254
+ <p align="right">
255
+ <a href="#_TOP">[Go Top]</a>
256
+ <hr/>
257
+ <a name="/Q2:_Installation_and_running_the_program"></a>
258
+ <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>
259
+ <br/>
260
+
261
+ <p>
262
+ This usually happens if you compile the code
263
+ on one machine and run it on another which has incompatible
264
+ libraries.
265
+ Try to recompile the program on that machine or use static linking.
266
+ <p align="right">
267
+ <a href="#_TOP">[Go Top]</a>
268
+ <hr/>
269
+ <a name="/Q2:_Installation_and_running_the_program"></a>
270
+ <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>
271
+ <br/>
272
+
273
+ <p>
274
+ Build it as a project by choosing "Win32 Project."
275
+ On the other hand, for "svm-train" and "svm-predict"
276
+ you want to choose "Win32 Console Project."
277
+ After libsvm 2.5, you can also use the file Makefile.win.
278
+ See details in README.
279
+
280
+
281
+ <p>
282
+ If you are not using Makefile.win and see the following
283
+ link error
284
+ <pre>
285
+ LIBCMTD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol
286
+ _wWinMain@16
287
+ </pre>
288
+ you may have selected a wrong project type.
289
+ <p align="right">
290
+ <a href="#_TOP">[Go Top]</a>
291
+ <hr/>
292
+ <a name="/Q2:_Installation_and_running_the_program"></a>
293
+ <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>
294
+ <br/>
295
+
296
+ <p>
297
+ You need to open a command window
298
+ and type svmtrain.exe to see all options.
299
+ Some examples are in README file.
300
+ <p align="right">
301
+ <a href="#_TOP">[Go Top]</a>
302
+ <hr/>
303
+ <a name="/Q2:_Installation_and_running_the_program"></a>
304
+ <a name="f209"><b>Q: What is the difference between "." and "*" outputed during training? </b></a>
305
+ <br/>
306
+
307
+ <p>
308
+ "." means every 1,000 iterations (or every #data
309
+ iterations is your #data is less than 1,000).
310
+ "*" means that after iterations of using
311
+ a smaller shrunk problem,
312
+ we reset to use the whole set. See the
313
+ <a href=../papers/libsvm.pdf>implementation document</a> for details.
314
+ <p align="right">
315
+ <a href="#_TOP">[Go Top]</a>
316
+ <hr/>
317
+ <a name="/Q2:_Installation_and_running_the_program"></a>
318
+ <a name="f210"><b>Q: Why occasionally the program (including MATLAB or other interfaces) crashes and gives a segmentation fault?</b></a>
319
+ <br/>
320
+
321
+ <p>
322
+ Very likely the program consumes too much memory than what the
323
+ operating system can provide. Try a smaller data and see if the
324
+ program still crashes.
325
+ <p align="right">
326
+ <a href="#_TOP">[Go Top]</a>
327
+ <hr/>
328
+ <a name="/Q3:_Data_preparation"></a>
329
+ <a name="f301"><b>Q: Why sometimes not all attributes of a data appear in the training/model files ?</b></a>
330
+ <br/>
331
+ <p>
332
+ libsvm uses the so called "sparse" format where zero
333
+ values do not need to be stored. Hence a data with attributes
334
+ <pre>
335
+ 1 0 2 0
336
+ </pre>
337
+ is represented as
338
+ <pre>
339
+ 1:1 3:2
340
+ </pre>
341
+ <p align="right">
342
+ <a href="#_TOP">[Go Top]</a>
343
+ <hr/>
344
+ <a name="/Q3:_Data_preparation"></a>
345
+ <a name="f302"><b>Q: What if my data are non-numerical ?</b></a>
346
+ <br/>
347
+ <p>
348
+ Currently libsvm supports only numerical data.
349
+ You may have to change non-numerical data to
350
+ numerical. For example, you can use several
351
+ binary attributes to represent a categorical
352
+ attribute.
353
+ <p align="right">
354
+ <a href="#_TOP">[Go Top]</a>
355
+ <hr/>
356
+ <a name="/Q3:_Data_preparation"></a>
357
+ <a name="f303"><b>Q: Why do you consider sparse format ? Will the training of dense data be much slower ?</b></a>
358
+ <br/>
359
+ <p>
360
+ This is a controversial issue. The kernel
361
+ evaluation (i.e. inner product) of sparse vectors is slower
362
+ so the total training time can be at least twice or three times
363
+ of that using the dense format.
364
+ However, we cannot support only dense format as then we CANNOT
365
+ handle extremely sparse cases. Simplicity of the code is another
366
+ concern. Right now we decide to support
367
+ the sparse format only.
368
+ <p align="right">
369
+ <a href="#_TOP">[Go Top]</a>
370
+ <hr/>
371
+ <a name="/Q3:_Data_preparation"></a>
372
+ <a name="f304"><b>Q: Why sometimes the last line of my data is not read by svm-train?</b></a>
373
+ <br/>
374
+
375
+ <p>
376
+ We assume that you have '\n' in the end of
377
+ each line. So please press enter in the end
378
+ of your last line.
379
+ <p align="right">
380
+ <a href="#_TOP">[Go Top]</a>
381
+ <hr/>
382
+ <a name="/Q3:_Data_preparation"></a>
383
+ <a name="f305"><b>Q: Is there a program to check if my data are in the correct format?</b></a>
384
+ <br/>
385
+
386
+ <p>
387
+ The svm-train program in libsvm conducts only a simple check of the input data. To do a
388
+ detailed check, after libsvm 2.85, you can use the python script tools/checkdata.py. See tools/README for details.
389
+ <p align="right">
390
+ <a href="#_TOP">[Go Top]</a>
391
+ <hr/>
392
+ <a name="/Q3:_Data_preparation"></a>
393
+ <a name="f306"><b>Q: May I put comments in data files?</b></a>
394
+ <br/>
395
+
396
+ <p>
397
+ No, for simplicity we don't support that.
398
+ However, you can easily preprocess your data before
399
+ using libsvm. For example,
400
+ if you have the following data
401
+ <pre>
402
+ test.txt
403
+ 1 1:2 2:1 # proten A
404
+ </pre>
405
+ then on unix machines you can do
406
+ <pre>
407
+ cut -d '#' -f 1 < test.txt > test.features
408
+ cut -d '#' -f 2 < test.txt > test.comments
409
+ svm-predict test.feature train.model test.predicts
410
+ paste -d '#' test.predicts test.comments | sed 's/#/ #/' > test.results
411
+ </pre>
412
+ <p align="right">
413
+ <a href="#_TOP">[Go Top]</a>
414
+ <hr/>
415
+ <a name="/Q3:_Data_preparation"></a>
416
+ <a name="f307"><b>Q: How to convert other data formats to LIBSVM format?</b></a>
417
+ <br/>
418
+
419
+ <p>
420
+ It depends on your data format.
421
+ We have a simple C code to transfer space/colon
422
+ separated format to libsvm format. Please contact
423
+ us if needed.
424
+
425
+ <p>
426
+ Alternatively, a simple way is to use
427
+ libsvmwrite in the libsvm matlab/octave interface.
428
+
429
+ Take a CSV (colon separated format) file
430
+ in UCI machine learning repository as an example.
431
+ We download <a href=http://archive.ics.uci.edu/ml/machine-learning-databases/spect/SPECTF.train>SPECTF.train</a>.
432
+ Labels are in the first column. The following steps produce
433
+ a file in the libsvm format.
434
+ <pre>
435
+ matlab> SPECTF = csvread('SPECTF.train'); % read a csv file
436
+ matlab> labels = SPECTF(:, 1); % labels from the 1st column
437
+ matlab> features = SPECTF(:, 2:end);
438
+ matlab> features_sparse = sparse(features); % features must be in a sparse matrix
439
+ matlab> libsvmwrite('SPECTFlibsvm.train', labels, features_sparse);
440
+ </pre>
441
+ The tranformed data are stored in SPECTFlibsvm.train.
442
+ <p align="right">
443
+ <a href="#_TOP">[Go Top]</a>
444
+ <hr/>
445
+ <a name="/Q4:_Training_and_prediction"></a>
446
+ <a name="f401"><b>Q: The output of training C-SVM is like the following. What do they mean?</b></a>
447
+ <br/>
448
+ <br>optimization finished, #iter = 219
449
+ <br>nu = 0.431030
450
+ <br>obj = -100.877286, rho = 0.424632
451
+ <br>nSV = 132, nBSV = 107
452
+ <br>Total nSV = 132
453
+ <p>
454
+ obj is the optimal objective value of the dual SVM problem.
455
+ rho is the bias term in the decision function
456
+ sgn(w^Tx - rho).
457
+ nSV and nBSV are number of support vectors and bounded support
458
+ vectors (i.e., alpha_i = C). nu-svm is a somewhat equivalent
459
+ form of C-SVM where C is replaced by nu. nu simply shows the
460
+ corresponding parameter. More details are in
461
+ <a href="http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf">
462
+ libsvm document</a>.
463
+ <p align="right">
464
+ <a href="#_TOP">[Go Top]</a>
465
+ <hr/>
466
+ <a name="/Q4:_Training_and_prediction"></a>
467
+ <a name="f402"><b>Q: Can you explain more about the model file?</b></a>
468
+ <br/>
469
+
470
+ <p>
471
+ After the parameters, each line represents a support vector.
472
+ Support vectors are listed in the order of "labels" listed earlier.
473
+ (i.e., those from the first class in the "labels" list are
474
+ grouped first, and so on.)
475
+ If k is the total number of classes,
476
+ in front of a support vector in class j, there are
477
+ k-1 coefficients
478
+ y*alpha where alpha are dual solution of the
479
+ following two class problems:
480
+ <br>
481
+ 1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k
482
+ <br>
483
+ and y=1 in first j-1 coefficients, y=-1 in the remaining
484
+ k-j coefficients.
485
+
486
+ For example, if there are 4 classes, the file looks like:
487
+
488
+ <pre>
489
+ +-+-+-+--------------------+
490
+ |1|1|1| |
491
+ |v|v|v| SVs from class 1 |
492
+ |2|3|4| |
493
+ +-+-+-+--------------------+
494
+ |1|2|2| |
495
+ |v|v|v| SVs from class 2 |
496
+ |2|3|4| |
497
+ +-+-+-+--------------------+
498
+ |1|2|3| |
499
+ |v|v|v| SVs from class 3 |
500
+ |3|3|4| |
501
+ +-+-+-+--------------------+
502
+ |1|2|3| |
503
+ |v|v|v| SVs from class 4 |
504
+ |4|4|4| |
505
+ +-+-+-+--------------------+
506
+ </pre>
507
+ See also
508
+ <a href="#f804"> an illustration using
509
+ MATLAB/OCTAVE.</a>
510
+ <p align="right">
511
+ <a href="#_TOP">[Go Top]</a>
512
+ <hr/>
513
+ <a name="/Q4:_Training_and_prediction"></a>
514
+ <a name="f403"><b>Q: Should I use float or double to store numbers in the cache ?</b></a>
515
+ <br/>
516
+
517
+ <p>
518
+ We have float as the default as you can store more numbers
519
+ in the cache.
520
+ In general this is good enough but for few difficult
521
+ cases (e.g. C very very large) where solutions are huge
522
+ numbers, it might be possible that the numerical precision is not
523
+ enough using only float.
524
+ <p align="right">
525
+ <a href="#_TOP">[Go Top]</a>
526
+ <hr/>
527
+ <a name="/Q4:_Training_and_prediction"></a>
528
+ <a name="f404"><b>Q: How do I choose the kernel?</b></a>
529
+ <br/>
530
+
531
+ <p>
532
+ In general we suggest you to try the RBF kernel first.
533
+ A recent result by Keerthi and Lin
534
+ (<a href=http://www.csie.ntu.edu.tw/~cjlin/papers/limit.pdf>
535
+ download paper here</a>)
536
+ shows that if RBF is used with model selection,
537
+ then there is no need to consider the linear kernel.
538
+ The kernel matrix using sigmoid may not be positive definite
539
+ and in general it's accuracy is not better than RBF.
540
+ (see the paper by Lin and Lin
541
+ (<a href=http://www.csie.ntu.edu.tw/~cjlin/papers/tanh.pdf>
542
+ download paper here</a>).
543
+ Polynomial kernels are ok but if a high degree is used,
544
+ numerical difficulties tend to happen
545
+ (thinking about dth power of (<1) goes to 0
546
+ and (>1) goes to infinity).
547
+ <p align="right">
548
+ <a href="#_TOP">[Go Top]</a>
549
+ <hr/>
550
+ <a name="/Q4:_Training_and_prediction"></a>
551
+ <a name="f405"><b>Q: Does libsvm have special treatments for linear SVM?</b></a>
552
+ <br/>
553
+
554
+ <p>
555
+
556
+ No, libsvm solves linear/nonlinear SVMs by the
557
+ same way.
558
+ Some tricks may save training/testing time if the
559
+ linear kernel is used,
560
+ so libsvm is <b>NOT</b> particularly efficient for linear SVM,
561
+ especially when
562
+ C is large and
563
+ the number of data is much larger
564
+ than the number of attributes.
565
+ You can either
566
+ <ul>
567
+ <li>
568
+ Use small C only. We have shown in the following paper
569
+ that after C is larger than a certain threshold,
570
+ the decision function is the same.
571
+ <p>
572
+ <a href="http://guppy.mpe.nus.edu.sg/~mpessk/">S. S. Keerthi</a>
573
+ and
574
+ <B>C.-J. Lin</B>.
575
+ <A HREF="papers/limit.pdf">
576
+ Asymptotic behaviors of support vector machines with
577
+ Gaussian kernel
578
+ </A>
579
+ .
580
+ <I><A HREF="http://mitpress.mit.edu/journal-home.tcl?issn=08997667">Neural Computation</A></I>, 15(2003), 1667-1689.
581
+
582
+
583
+ <li>
584
+ Check <a href=http://www.csie.ntu.edu.tw/~cjlin/liblinear>liblinear</a>,
585
+ which is designed for large-scale linear classification.
586
+ </ul>
587
+
588
+ <p> Please also see our <a href=../papers/guide/guide.pdf>SVM guide</a>
589
+ on the discussion of using RBF and linear
590
+ kernels.
591
+ <p align="right">
592
+ <a href="#_TOP">[Go Top]</a>
593
+ <hr/>
594
+ <a name="/Q4:_Training_and_prediction"></a>
595
+ <a name="f406"><b>Q: The number of free support vectors is large. What should I do?</b></a>
596
+ <br/>
597
+ <p>
598
+ This usually happens when the data are overfitted.
599
+ If attributes of your data are in large ranges,
600
+ try to scale them. Then the region
601
+ of appropriate parameters may be larger.
602
+ Note that there is a scale program
603
+ in libsvm.
604
+ <p align="right">
605
+ <a href="#_TOP">[Go Top]</a>
606
+ <hr/>
607
+ <a name="/Q4:_Training_and_prediction"></a>
608
+ <a name="f407"><b>Q: Should I scale training and testing data in a similar way?</b></a>
609
+ <br/>
610
+ <p>
611
+ Yes, you can do the following:
612
+ <pre>
613
+ > svm-scale -s scaling_parameters train_data > scaled_train_data
614
+ > svm-scale -r scaling_parameters test_data > scaled_test_data
615
+ </pre>
616
+ <p align="right">
617
+ <a href="#_TOP">[Go Top]</a>
618
+ <hr/>
619
+ <a name="/Q4:_Training_and_prediction"></a>
620
+ <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>
621
+ <br/>
622
+
623
+ <p>
624
+ For the linear scaling method, if the RBF kernel is
625
+ used and parameter selection is conducted, there
626
+ is no difference. Assume Mi and mi are
627
+ respectively the maximal and minimal values of the
628
+ ith attribute. Scaling to [0,1] means
629
+ <pre>
630
+ x'=(x-mi)/(Mi-mi)
631
+ </pre>
632
+ For [-1,1],
633
+ <pre>
634
+ x''=2(x-mi)/(Mi-mi)-1.
635
+ </pre>
636
+ In the RBF kernel,
637
+ <pre>
638
+ x'-y'=(x-y)/(Mi-mi), x''-y''=2(x-y)/(Mi-mi).
639
+ </pre>
640
+ Hence, using (C,g) on the [0,1]-scaled data is the
641
+ same as (C,g/2) on the [-1,1]-scaled data.
642
+
643
+ <p> Though the performance is the same, the computational
644
+ time may be different. For data with many zero entries,
645
+ [0,1]-scaling keeps the sparsity of input data and hence
646
+ may save the time.
647
+ <p align="right">
648
+ <a href="#_TOP">[Go Top]</a>
649
+ <hr/>
650
+ <a name="/Q4:_Training_and_prediction"></a>
651
+ <a name="f409"><b>Q: The prediction rate is low. How could I improve it?</b></a>
652
+ <br/>
653
+ <p>
654
+ Try to use the model selection tool grid.py in the python
655
+ directory find
656
+ out good parameters. To see the importance of model selection,
657
+ please
658
+ see my talk:
659
+ <A HREF="http://www.csie.ntu.edu.tw/~cjlin/talks/freiburg.pdf">
660
+ A practical guide to support vector
661
+ classification
662
+ </A>
663
+ <p align="right">
664
+ <a href="#_TOP">[Go Top]</a>
665
+ <hr/>
666
+ <a name="/Q4:_Training_and_prediction"></a>
667
+ <a name="f410"><b>Q: My data are unbalanced. Could libsvm handle such problems?</b></a>
668
+ <br/>
669
+ <p>
670
+ Yes, there is a -wi options. For example, if you use
671
+ <pre>
672
+ > svm-train -s 0 -c 10 -w1 1 -w-1 5 data_file
673
+ </pre>
674
+ <p>
675
+ the penalty for class "-1" is larger.
676
+ Note that this -w option is for C-SVC only.
677
+ <p align="right">
678
+ <a href="#_TOP">[Go Top]</a>
679
+ <hr/>
680
+ <a name="/Q4:_Training_and_prediction"></a>
681
+ <a name="f411"><b>Q: What is the difference between nu-SVC and C-SVC?</b></a>
682
+ <br/>
683
+ <p>
684
+ Basically they are the same thing but with different
685
+ parameters. The range of C is from zero to infinity
686
+ but nu is always between [0,1]. A nice property
687
+ of nu is that it is related to the ratio of
688
+ support vectors and the ratio of the training
689
+ error.
690
+ <p align="right">
691
+ <a href="#_TOP">[Go Top]</a>
692
+ <hr/>
693
+ <a name="/Q4:_Training_and_prediction"></a>
694
+ <a name="f412"><b>Q: The program keeps running (without showing any output). What should I do?</b></a>
695
+ <br/>
696
+ <p>
697
+ You may want to check your data. Each training/testing
698
+ data must be in one line. It cannot be separated.
699
+ In addition, you have to remove empty lines.
700
+ <p align="right">
701
+ <a href="#_TOP">[Go Top]</a>
702
+ <hr/>
703
+ <a name="/Q4:_Training_and_prediction"></a>
704
+ <a name="f413"><b>Q: The program keeps running (with output, i.e. many dots). What should I do?</b></a>
705
+ <br/>
706
+ <p>
707
+ In theory libsvm guarantees to converge.
708
+ Therefore, this means you are
709
+ handling ill-conditioned situations
710
+ (e.g. too large/small parameters) so numerical
711
+ difficulties occur.
712
+ <p align="right">
713
+ <a href="#_TOP">[Go Top]</a>
714
+ <hr/>
715
+ <a name="/Q4:_Training_and_prediction"></a>
716
+ <a name="f414"><b>Q: The training time is too long. What should I do?</b></a>
717
+ <br/>
718
+ <p>
719
+ For large problems, please specify enough cache size (i.e.,
720
+ -m).
721
+ Slow convergence may happen for some difficult cases (e.g. -c is large).
722
+ You can try to use a looser stopping tolerance with -e.
723
+ If that still doesn't work, you may train only a subset of the data.
724
+ You can use the program subset.py in the directory "tools"
725
+ to obtain a random subset.
726
+
727
+ <p>
728
+ If you have extremely large data and face this difficulty, please
729
+ contact us. We will be happy to discuss possible solutions.
730
+
731
+ <p> When using large -e, you may want to check if -h 0 (no shrinking) or -h 1 (shrinking) is faster.
732
+ See a related question below.
733
+
734
+ <p align="right">
735
+ <a href="#_TOP">[Go Top]</a>
736
+ <hr/>
737
+ <a name="/Q4:_Training_and_prediction"></a>
738
+ <a name="f4141"><b>Q: Does shrinking always help?</b></a>
739
+ <br/>
740
+ <p>
741
+ If the number of iterations is high, then shrinking
742
+ often helps.
743
+ However, if the number of iterations is small
744
+ (e.g., you specify a large -e), then
745
+ probably using -h 0 (no shrinking) is better.
746
+ See the
747
+ <a href=../papers/libsvm.pdf>implementation document</a> for details.
748
+ <p align="right">
749
+ <a href="#_TOP">[Go Top]</a>
750
+ <hr/>
751
+ <a name="/Q4:_Training_and_prediction"></a>
752
+ <a name="f415"><b>Q: How do I get the decision value(s)?</b></a>
753
+ <br/>
754
+ <p>
755
+ We print out decision values for regression. For classification,
756
+ we solve several binary SVMs for multi-class cases. You
757
+ can obtain values by easily calling the subroutine
758
+ svm_predict_values. Their corresponding labels
759
+ can be obtained from svm_get_labels.
760
+ Details are in
761
+ README of libsvm package.
762
+
763
+ <p>
764
+ We do not recommend the following. But if you would
765
+ like to get values for
766
+ TWO-class classification with labels +1 and -1
767
+ (note: +1 and -1 but not things like 5 and 10)
768
+ in the easiest way, simply add
769
+ <pre>
770
+ printf("%f\n", dec_values[0]*model->label[0]);
771
+ </pre>
772
+ after the line
773
+ <pre>
774
+ svm_predict_values(model, x, dec_values);
775
+ </pre>
776
+ of the file svm.cpp.
777
+ Positive (negative)
778
+ decision values correspond to data predicted as +1 (-1).
779
+
780
+
781
+ <p align="right">
782
+ <a href="#_TOP">[Go Top]</a>
783
+ <hr/>
784
+ <a name="/Q4:_Training_and_prediction"></a>
785
+ <a name="f4151"><b>Q: How do I get the distance between a point and the hyperplane?</b></a>
786
+ <br/>
787
+ <p>
788
+ The distance is |decision_value| / |w|.
789
+ We have |w|^2 = w^Tw = alpha^T Q alpha = 2*(dual_obj + sum alpha_i).
790
+ Thus in svm.cpp please find the place
791
+ where we calculate the dual objective value
792
+ (i.e., the subroutine Solve())
793
+ and add a statement to print w^Tw.
794
+
795
+ <p align="right">
796
+ <a href="#_TOP">[Go Top]</a>
797
+ <hr/>
798
+ <a name="/Q4:_Training_and_prediction"></a>
799
+ <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>
800
+ <br/>
801
+ <p>
802
+
803
+ On 32-bit machines, the maximum addressable
804
+ memory is 4GB. The Linux kernel uses 3:1
805
+ split which means user space is 3G and
806
+ kernel space is 1G. Although there are
807
+ 3G user space, the maximum dynamic allocation
808
+ memory is 2G. So, if you specify -m near 2G,
809
+ the memory will be exhausted. And svm-train
810
+ will fail when it asks more memory.
811
+ For more details, please read
812
+ <a href=http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=3BA164F6.BAFA4FB%40daimi.au.dk>
813
+ this article</a>.
814
+ <p>
815
+ The easiest solution is to switch to a
816
+ 64-bit machine.
817
+ Otherwise, there are two ways to solve this. If your
818
+ machine supports Intel's PAE (Physical Address
819
+ Extension), you can turn on the option HIGHMEM64G
820
+ in Linux kernel which uses 4G:4G split for
821
+ kernel and user space. If you don't, you can
822
+ try a software `tub' which can eliminate the 2G
823
+ boundary for dynamic allocated memory. The `tub'
824
+ is available at
825
+ <a href=http://www.bitwagon.com/tub.html>http://www.bitwagon.com/tub.html</a>.
826
+
827
+
828
+ <!--
829
+
830
+ This may happen only when the cache is large, but each cached row is
831
+ not large enough. <b>Note:</b> This problem is specific to
832
+ gnu C library which is used in linux.
833
+ The solution is as follows:
834
+
835
+ <p>
836
+ In our program we have malloc() which uses two methods
837
+ to allocate memory from kernel. One is
838
+ sbrk() and another is mmap(). sbrk is faster, but mmap
839
+ has a larger address
840
+ space. So malloc uses mmap only if the wanted memory size is larger
841
+ than some threshold (default 128k).
842
+ In the case where each row is not large enough (#elements < 128k/sizeof(float)) but we need a large cache ,
843
+ the address space for sbrk can be exhausted. The solution is to
844
+ lower the threshold to force malloc to use mmap
845
+ and increase the maximum number of chunks to allocate
846
+ with mmap.
847
+
848
+ <p>
849
+ Therefore, in the main program (i.e. svm-train.c) you want
850
+ to have
851
+ <pre>
852
+ #include &lt;malloc.h&gt;
853
+ </pre>
854
+ and then in main():
855
+ <pre>
856
+ mallopt(M_MMAP_THRESHOLD, 32768);
857
+ mallopt(M_MMAP_MAX,1000000);
858
+ </pre>
859
+ You can also set the environment variables instead
860
+ of writing them in the program:
861
+ <pre>
862
+ $ M_MMAP_MAX=1000000 M_MMAP_THRESHOLD=32768 ./svm-train .....
863
+ </pre>
864
+ More information can be found by
865
+ <pre>
866
+ $ info libc "Malloc Tunable Parameters"
867
+ </pre>
868
+ -->
869
+ <p align="right">
870
+ <a href="#_TOP">[Go Top]</a>
871
+ <hr/>
872
+ <a name="/Q4:_Training_and_prediction"></a>
873
+ <a name="f417"><b>Q: How do I disable screen output of svm-train and svm-predict ?</b></a>
874
+ <br/>
875
+ <p>
876
+ For commend-line users, use the -q option:
877
+ <pre>
878
+ > ./svm-train -q heart_scale
879
+ </pre>
880
+ <p>
881
+ For library users, set the global variable
882
+ <pre>
883
+ extern void (*svm_print_string) (const char *);
884
+ </pre>
885
+ to specify the output format. You can disable the output by the following steps:
886
+ <ol>
887
+ <li>
888
+ Declare a function to output nothing:
889
+ <pre>
890
+ void print_null(const char *s) {}
891
+ </pre>
892
+ </li>
893
+ <li>
894
+ Assign the output function of libsvm by
895
+ <pre>
896
+ svm_print_string = &print_null;
897
+ </pre>
898
+ </li>
899
+ </ol>
900
+ Finally, a way used in earlier libsvm
901
+ is by updating svm.cpp from
902
+ <pre>
903
+ #if 1
904
+ void info(const char *fmt,...)
905
+ </pre>
906
+ to
907
+ <pre>
908
+ #if 0
909
+ void info(const char *fmt,...)
910
+ </pre>
911
+ <p align="right">
912
+ <a href="#_TOP">[Go Top]</a>
913
+ <hr/>
914
+ <a name="/Q4:_Training_and_prediction"></a>
915
+ <a name="f418"><b>Q: I would like to use my own kernel but find out that there are two subroutines for kernel evaluations: k_function() and kernel_function(). Which one should I modify ?</b></a>
916
+ <br/>
917
+ <p>
918
+ The reason why we have two functions is as follows:
919
+ For the RBF kernel exp(-g |xi - xj|^2), if we calculate
920
+ xi - xj first and then the norm square, there are 3n operations.
921
+ Thus we consider exp(-g (|xi|^2 - 2dot(xi,xj) +|xj|^2))
922
+ and by calculating all |xi|^2 in the beginning,
923
+ the number of operations is reduced to 2n.
924
+ This is for the training. For prediction we cannot
925
+ do this so a regular subroutine using that 3n operations is
926
+ needed.
927
+
928
+ The easiest way to have your own kernel is
929
+ to put the same code in these two
930
+ subroutines by replacing any kernel.
931
+ <p align="right">
932
+ <a href="#_TOP">[Go Top]</a>
933
+ <hr/>
934
+ <a name="/Q4:_Training_and_prediction"></a>
935
+ <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>
936
+ <br/>
937
+ <p>
938
+ It is one-against-one. We chose it after doing the following
939
+ comparison:
940
+ C.-W. Hsu and C.-J. Lin.
941
+ <A HREF="http://www.csie.ntu.edu.tw/~cjlin/papers/multisvm.pdf">
942
+ A comparison of methods
943
+ for multi-class support vector machines
944
+ </A>,
945
+ <I>IEEE Transactions on Neural Networks</A></I>, 13(2002), 415-425.
946
+
947
+ <p>
948
+ "1-against-the rest" is a good method whose performance
949
+ is comparable to "1-against-1." We do the latter
950
+ simply because its training time is shorter.
951
+ <p align="right">
952
+ <a href="#_TOP">[Go Top]</a>
953
+ <hr/>
954
+ <a name="/Q4:_Training_and_prediction"></a>
955
+ <a name="f420"><b>Q: After doing cross validation, why there is no model file outputted ?</b></a>
956
+ <br/>
957
+ <p>
958
+ Cross validation is used for selecting good parameters.
959
+ After finding them, you want to re-train the whole
960
+ data without the -v option.
961
+ <p align="right">
962
+ <a href="#_TOP">[Go Top]</a>
963
+ <hr/>
964
+ <a name="/Q4:_Training_and_prediction"></a>
965
+ <a name="f4201"><b>Q: Why my cross-validation results are different from those in the Practical Guide?</b></a>
966
+ <br/>
967
+ <p>
968
+
969
+ Due to random partitions of
970
+ the data, on different systems CV accuracy values
971
+ may be different.
972
+ <p align="right">
973
+ <a href="#_TOP">[Go Top]</a>
974
+ <hr/>
975
+ <a name="/Q4:_Training_and_prediction"></a>
976
+ <a name="f421"><b>Q: But on some systems CV accuracy is the same in several runs. How could I use different data partitions?</b></a>
977
+ <br/>
978
+ <p>
979
+ If you use GNU C library,
980
+ the default seed 1 is considered. Thus you always
981
+ get the same result of running svm-train -v.
982
+ To have different seeds, you can add the following code
983
+ in svm-train.c:
984
+ <pre>
985
+ #include &lt;time.h&gt;
986
+ </pre>
987
+ and in the beginning of the subroutine do_cross_validation(),
988
+ <pre>
989
+ srand(time(0));
990
+ </pre>
991
+ <p align="right">
992
+ <a href="#_TOP">[Go Top]</a>
993
+ <hr/>
994
+ <a name="/Q4:_Training_and_prediction"></a>
995
+ <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>
996
+ <br/>
997
+ <p>
998
+ It is extremely easy. Taking c-svc for example, to solve
999
+ <p>
1000
+ min_w w^Tw/2 + C \sum max(0, 1- (y_i w^Tx_i+b))^2,
1001
+ <p>
1002
+ only two
1003
+ places of svm.cpp have to be changed.
1004
+ First, modify the following line of
1005
+ solve_c_svc from
1006
+ <pre>
1007
+ s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
1008
+ alpha, Cp, Cn, param->eps, si, param->shrinking);
1009
+ </pre>
1010
+ to
1011
+ <pre>
1012
+ s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
1013
+ alpha, INF, INF, param->eps, si, param->shrinking);
1014
+ </pre>
1015
+ Second, in the class of SVC_Q, declare C as
1016
+ a private variable:
1017
+ <pre>
1018
+ double C;
1019
+ </pre>
1020
+ In the constructor replace
1021
+ <pre>
1022
+ for(int i=0;i<prob.l;i++)
1023
+ QD[i]= (Qfloat)(this->*kernel_function)(i,i);
1024
+ </pre>
1025
+ with
1026
+ <pre>
1027
+ this->C = param.C;
1028
+ for(int i=0;i<prob.l;i++)
1029
+ QD[i]= (Qfloat)(this->*kernel_function)(i,i)+0.5/C;
1030
+ </pre>
1031
+ Then in the subroutine get_Q, after the for loop, add
1032
+ <pre>
1033
+ if(i >= start && i < len)
1034
+ data[i] += 0.5/C;
1035
+ </pre>
1036
+
1037
+ <p>
1038
+ 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:
1039
+ <pre>
1040
+ data[real_i] += 0.5/C;
1041
+ </pre>
1042
+
1043
+
1044
+ <p>
1045
+ For large linear L2-loss SVM, please use
1046
+ <a href=../liblinear>LIBLINEAR</a>.
1047
+ <p align="right">
1048
+ <a href="#_TOP">[Go Top]</a>
1049
+ <hr/>
1050
+ <a name="/Q4:_Training_and_prediction"></a>
1051
+ <a name="f424"><b>Q: How do I choose parameters for one-class svm as training data are in only one class?</b></a>
1052
+ <br/>
1053
+ <p>
1054
+ You have pre-specified true positive rate in mind and then search for
1055
+ parameters which achieve similar cross-validation accuracy.
1056
+ <p align="right">
1057
+ <a href="#_TOP">[Go Top]</a>
1058
+ <hr/>
1059
+ <a name="/Q4:_Training_and_prediction"></a>
1060
+ <a name="f427"><b>Q: Why the code gives NaN (not a number) results?</b></a>
1061
+ <br/>
1062
+ <p>
1063
+ This rarely happens, but few users reported the problem.
1064
+ It seems that their
1065
+ computers for training libsvm have the VPN client
1066
+ running. The VPN software has some bugs and causes this
1067
+ problem. Please try to close or disconnect the VPN client.
1068
+ <p align="right">
1069
+ <a href="#_TOP">[Go Top]</a>
1070
+ <hr/>
1071
+ <a name="/Q4:_Training_and_prediction"></a>
1072
+ <a name="f428"><b>Q: Why on windows sometimes grid.py fails?</b></a>
1073
+ <br/>
1074
+ <p>
1075
+
1076
+ This problem shouldn't happen after version
1077
+ 2.85. If you are using earlier versions,
1078
+ please download the latest one.
1079
+
1080
+ <!--
1081
+ <p>
1082
+ If you are using earlier
1083
+ versions, the error message is probably
1084
+ <pre>
1085
+ Traceback (most recent call last):
1086
+ File "grid.py", line 349, in ?
1087
+ main()
1088
+ File "grid.py", line 344, in main
1089
+ redraw(db)
1090
+ File "grid.py", line 132, in redraw
1091
+ gnuplot.write("set term windows\n")
1092
+ IOError: [Errno 22] Invalid argument
1093
+ </pre>
1094
+
1095
+ <p>Please try to close gnuplot windows and rerun.
1096
+ If the problem still occurs, comment the following
1097
+ two lines in grid.py by inserting "#" in the beginning:
1098
+ <pre>
1099
+ redraw(db)
1100
+ redraw(db,1)
1101
+ </pre>
1102
+ Then you get accuracy only but not cross validation contours.
1103
+ -->
1104
+ <p align="right">
1105
+ <a href="#_TOP">[Go Top]</a>
1106
+ <hr/>
1107
+ <a name="/Q4:_Training_and_prediction"></a>
1108
+ <a name="f429"><b>Q: Why grid.py/easy.py sometimes generates the following warning message?</b></a>
1109
+ <br/>
1110
+ <pre>
1111
+ Warning: empty z range [62.5:62.5], adjusting to [61.875:63.125]
1112
+ Notice: cannot contour non grid data!
1113
+ </pre>
1114
+ <p>Nothing is wrong and please disregard the
1115
+ message. It is from gnuplot when drawing
1116
+ the contour.
1117
+ <p align="right">
1118
+ <a href="#_TOP">[Go Top]</a>
1119
+ <hr/>
1120
+ <a name="/Q4:_Training_and_prediction"></a>
1121
+ <a name="f430"><b>Q: Why the sign of predicted labels and decision values are sometimes reversed?</b></a>
1122
+ <br/>
1123
+ <p>Nothing is wrong. Very likely you have two labels +1/-1 and the first instance in your data
1124
+ has -1.
1125
+ Think about the case of labels +5/+10. Since
1126
+ SVM needs to use +1/-1, internally
1127
+ we map +5/+10 to +1/-1 according to which
1128
+ label appears first.
1129
+ Hence a positive decision value implies
1130
+ that we should predict the "internal" +1,
1131
+ which may not be the +1 in the input file.
1132
+
1133
+ <p align="right">
1134
+ <a href="#_TOP">[Go Top]</a>
1135
+ <hr/>
1136
+ <a name="/Q4:_Training_and_prediction"></a>
1137
+ <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>
1138
+ <br/>
1139
+ <p>Any value is ok. In this situation, what you will use is the output file of svm-predict, which gives predicted class labels.
1140
+
1141
+
1142
+ <p align="right">
1143
+ <a href="#_TOP">[Go Top]</a>
1144
+ <hr/>
1145
+ <a name="/Q4:_Training_and_prediction"></a>
1146
+ <a name="f432"><b>Q: How can I use OpenMP to parallelize LIBSVM on a multicore/shared-memory computer?</b></a>
1147
+ <br/>
1148
+
1149
+ <p>It is very easy if you are using GCC 4.2
1150
+ or after.
1151
+
1152
+ <p> In Makefile, add -fopenmp to CFLAGS.
1153
+
1154
+ <p> In class SVC_Q of svm.cpp, modify the for loop
1155
+ of get_Q to:
1156
+ <pre>
1157
+ #pragma omp parallel for private(j)
1158
+ for(j=start;j&lt;len;j++)
1159
+ </pre>
1160
+ <p> In the subroutine svm_predict_values of svm.cpp, add one line to the for loop:
1161
+ <pre>
1162
+ #pragma omp parallel for private(i)
1163
+ for(i=0;i&lt;l;i++)
1164
+ kvalue[i] = Kernel::k_function(x,model-&gt;SV[i],model-&gt;param);
1165
+ </pre>
1166
+
1167
+ <p> Then rebuild the package. Kernel evaluations in training/testing will be parallelized. An example of running this modification on
1168
+ an 8-core machine using the data set
1169
+ <a href=../libsvmtools/datasets/binary/ijcnn1.bz2>ijcnn1</a>:
1170
+
1171
+ <p> 8 cores:
1172
+ <pre>
1173
+ %setenv OMP_NUM_THREADS 8
1174
+ %time svm-train -c 16 -g 4 -m 400 ijcnn1
1175
+ 27.1sec
1176
+ </pre>
1177
+ 1 core:
1178
+ <pre>
1179
+ %setenv OMP_NUM_THREADS 1
1180
+ %time svm-train -c 16 -g 4 -m 400 ijcnn1
1181
+ 79.8sec
1182
+ </pre>
1183
+ For this data, kernel evaluations take 80% of training time.
1184
+ <p align="right">
1185
+ <a href="#_TOP">[Go Top]</a>
1186
+ <hr/>
1187
+ <a name="/Q4:_Training_and_prediction"></a>
1188
+ <a name="f433"><b>Q: How could I know which training instances are support vectors?</b></a>
1189
+ <br/>
1190
+
1191
+ <p>
1192
+ It's very simple. Please replace
1193
+ <pre>
1194
+ if(nonzero[i]) model->SV[p++] = x[i];
1195
+ </pre>
1196
+ in svm_train() of svm.cpp with
1197
+ <pre>
1198
+ if(nonzero[i])
1199
+ {
1200
+ model->SV[p++] = x[i];
1201
+ info("%d\n", perm[i]);
1202
+ }
1203
+ </pre>
1204
+ If there are many requests, we may
1205
+ provide a function to return indices
1206
+ of support vectors. In the mean time,
1207
+ if you need such information in your code,
1208
+ you can add the array nonzero to the model
1209
+ structure. This array has the same size as
1210
+ the number of data, so alternatively you can
1211
+ store only indices of support vectors.
1212
+
1213
+ <p> If you use matlab interface, you can easily
1214
+ compare support vectors and training data to know
1215
+ the indices:
1216
+ <pre>
1217
+ [tmp index]=ismember(model.SVs, training_data,'rows');
1218
+ </pre>
1219
+ <p align="right">
1220
+ <a href="#_TOP">[Go Top]</a>
1221
+ <hr/>
1222
+ <a name="/Q5:_Probability_outputs"></a>
1223
+ <a name="f425"><b>Q: Why training a probability model (i.e., -b 1) takes a longer time?</b></a>
1224
+ <br/>
1225
+ <p>
1226
+ To construct this probability model, we internally conduct a
1227
+ cross validation, which is more time consuming than
1228
+ a regular training.
1229
+ Hence, in general you do parameter selection first without
1230
+ -b 1. You only use -b 1 when good parameters have been
1231
+ selected. In other words, you avoid using -b 1 and -v
1232
+ together.
1233
+ <p align="right">
1234
+ <a href="#_TOP">[Go Top]</a>
1235
+ <hr/>
1236
+ <a name="/Q5:_Probability_outputs"></a>
1237
+ <a name="f426"><b>Q: Why using the -b option does not give me better accuracy?</b></a>
1238
+ <br/>
1239
+ <p>
1240
+ There is absolutely no reason the probability outputs guarantee
1241
+ you better accuracy. The main purpose of this option is
1242
+ to provide you the probability estimates, but not to boost
1243
+ prediction accuracy. From our experience,
1244
+ after proper parameter selections, in general with
1245
+ and without -b have similar accuracy. Occasionally there
1246
+ are some differences.
1247
+ It is not recommended to compare the two under
1248
+ just a fixed parameter
1249
+ set as more differences will be observed.
1250
+ <p align="right">
1251
+ <a href="#_TOP">[Go Top]</a>
1252
+ <hr/>
1253
+ <a name="/Q5:_Probability_outputs"></a>
1254
+ <a name="f427"><b>Q: Why using svm-predict -b 0 and -b 1 gives different accuracy values?</b></a>
1255
+ <br/>
1256
+ <p>
1257
+ Let's just consider two-class classification here. After probability information is obtained in training,
1258
+ we do not have
1259
+ <p>
1260
+ prob > = 0.5 if and only if decision value >= 0.
1261
+ <p>
1262
+ So predictions may be different with -b 0 and 1.
1263
+ <p align="right">
1264
+ <a href="#_TOP">[Go Top]</a>
1265
+ <hr/>
1266
+ <a name="/Q6:_Graphic_interface"></a>
1267
+ <a name="f501"><b>Q: How can I save images drawn by svm-toy?</b></a>
1268
+ <br/>
1269
+ <p>
1270
+ For Microsoft windows, first press the "print screen" key on the keyboard.
1271
+ Open "Microsoft Paint"
1272
+ (included in Windows)
1273
+ and press "ctrl-v." Then you can clip
1274
+ the part of picture which you want.
1275
+ For X windows, you can
1276
+ use the program "xv" or "import" to grab the picture of the svm-toy window.
1277
+ <p align="right">
1278
+ <a href="#_TOP">[Go Top]</a>
1279
+ <hr/>
1280
+ <a name="/Q6:_Graphic_interface"></a>
1281
+ <a name="f502"><b>Q: I press the "load" button to load data points but why svm-toy does not draw them ?</b></a>
1282
+ <br/>
1283
+ <p>
1284
+ The program svm-toy assumes both attributes (i.e. x-axis and y-axis
1285
+ values) are in (0,1). Hence you want to scale your
1286
+ data to between a small positive number and
1287
+ a number less than but very close to 1.
1288
+ Moreover, class labels must be 1, 2, or 3
1289
+ (not 1.0, 2.0 or anything else).
1290
+ <p align="right">
1291
+ <a href="#_TOP">[Go Top]</a>
1292
+ <hr/>
1293
+ <a name="/Q6:_Graphic_interface"></a>
1294
+ <a name="f503"><b>Q: I would like svm-toy to handle more than three classes of data, what should I do ?</b></a>
1295
+ <br/>
1296
+ <p>
1297
+ Taking windows/svm-toy.cpp as an example, you need to
1298
+ modify it and the difference
1299
+ from the original file is as the following: (for five classes of
1300
+ data)
1301
+ <pre>
1302
+ 30,32c30
1303
+ < RGB(200,0,200),
1304
+ < RGB(0,160,0),
1305
+ < RGB(160,0,0)
1306
+ ---
1307
+ > RGB(200,0,200)
1308
+ 39c37
1309
+ < HBRUSH brush1, brush2, brush3, brush4, brush5;
1310
+ ---
1311
+ > HBRUSH brush1, brush2, brush3;
1312
+ 113,114d110
1313
+ < brush4 = CreateSolidBrush(colors[7]);
1314
+ < brush5 = CreateSolidBrush(colors[8]);
1315
+ 155,157c151
1316
+ < else if(v==3) return brush3;
1317
+ < else if(v==4) return brush4;
1318
+ < else return brush5;
1319
+ ---
1320
+ > else return brush3;
1321
+ 325d318
1322
+ < int colornum = 5;
1323
+ 327c320
1324
+ < svm_node *x_space = new svm_node[colornum * prob.l];
1325
+ ---
1326
+ > svm_node *x_space = new svm_node[3 * prob.l];
1327
+ 333,338c326,331
1328
+ < x_space[colornum * i].index = 1;
1329
+ < x_space[colornum * i].value = q->x;
1330
+ < x_space[colornum * i + 1].index = 2;
1331
+ < x_space[colornum * i + 1].value = q->y;
1332
+ < x_space[colornum * i + 2].index = -1;
1333
+ < prob.x[i] = &x_space[colornum * i];
1334
+ ---
1335
+ > x_space[3 * i].index = 1;
1336
+ > x_space[3 * i].value = q->x;
1337
+ > x_space[3 * i + 1].index = 2;
1338
+ > x_space[3 * i + 1].value = q->y;
1339
+ > x_space[3 * i + 2].index = -1;
1340
+ > prob.x[i] = &x_space[3 * i];
1341
+ 397c390
1342
+ < if(current_value > 5) current_value = 1;
1343
+ ---
1344
+ > if(current_value > 3) current_value = 1;
1345
+ </pre>
1346
+ <p align="right">
1347
+ <a href="#_TOP">[Go Top]</a>
1348
+ <hr/>
1349
+ <a name="/Q7:_Java_version_of_libsvm"></a>
1350
+ <a name="f601"><b>Q: What is the difference between Java version and C++ version of libsvm?</b></a>
1351
+ <br/>
1352
+ <p>
1353
+ They are the same thing. We just rewrote the C++ code
1354
+ in Java.
1355
+ <p align="right">
1356
+ <a href="#_TOP">[Go Top]</a>
1357
+ <hr/>
1358
+ <a name="/Q7:_Java_version_of_libsvm"></a>
1359
+ <a name="f602"><b>Q: Is the Java version significantly slower than the C++ version?</b></a>
1360
+ <br/>
1361
+ <p>
1362
+ This depends on the VM you used. We have seen good
1363
+ VM which leads the Java version to be quite competitive with
1364
+ the C++ code. (though still slower)
1365
+ <p align="right">
1366
+ <a href="#_TOP">[Go Top]</a>
1367
+ <hr/>
1368
+ <a name="/Q7:_Java_version_of_libsvm"></a>
1369
+ <a name="f603"><b>Q: While training I get the following error message: java.lang.OutOfMemoryError. What is wrong?</b></a>
1370
+ <br/>
1371
+ <p>
1372
+ You should try to increase the maximum Java heap size.
1373
+ For example,
1374
+ <pre>
1375
+ java -Xmx2048m -classpath libsvm.jar svm_train ...
1376
+ </pre>
1377
+ sets the maximum heap size to 2048M.
1378
+ <p align="right">
1379
+ <a href="#_TOP">[Go Top]</a>
1380
+ <hr/>
1381
+ <a name="/Q7:_Java_version_of_libsvm"></a>
1382
+ <a name="f604"><b>Q: Why you have the main source file svm.m4 and then transform it to svm.java?</b></a>
1383
+ <br/>
1384
+ <p>
1385
+ Unlike C, Java does not have a preprocessor built-in.
1386
+ However, we need some macros (see first 3 lines of svm.m4).
1387
+
1388
+ </ul>
1389
+ <p align="right">
1390
+ <a href="#_TOP">[Go Top]</a>
1391
+ <hr/>
1392
+ <a name="/Q8:_Python_interface"></a>
1393
+ <a name="f702"><b>Q: On MS windows, why does python fail to load the pyd file?</b></a>
1394
+ <br/>
1395
+ <p>
1396
+ It seems the pyd file is version dependent. So far we haven't
1397
+ found out a good solution. Please email us if you have any
1398
+ good suggestions.
1399
+ <p align="right">
1400
+ <a href="#_TOP">[Go Top]</a>
1401
+ <hr/>
1402
+ <a name="/Q8:_Python_interface"></a>
1403
+ <a name="f703"><b>Q: How to modify the python interface on MS windows and rebuild the .pyd file ?</b></a>
1404
+ <br/>
1405
+ <p>
1406
+
1407
+ To modify the interface, follow the instructions given in
1408
+ <a href=
1409
+ http://www.swig.org/Doc1.3/Python.html#Python>
1410
+ http://www.swig.org/Doc1.3/Python.html#Python
1411
+ </a>
1412
+
1413
+ <p>
1414
+
1415
+ If you just want to build .pyd for a different python version,
1416
+ after libsvm 2.5, you can easily use the file Makefile.win.
1417
+ See details in README.
1418
+
1419
+ Alternatively, you can use Visual C++. Here is
1420
+ the example using Visual Studio .Net 2005:
1421
+ <ol>
1422
+ <li>Create a Win32 DLL project and set (in Project->$Project_Name
1423
+ Properties...->Configuration) to "Release."
1424
+ About how to create a new dynamic link library, please refer to
1425
+ <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>
1426
+
1427
+ <li> Add svm.cpp, svmc_wrap.c, pythonXX.lib to your project.
1428
+ <li> Add the directories containing Python.h and svm.h to the Additional
1429
+ Include Directories(in Project->$Project_Name
1430
+ Properties...->C/C++->General)
1431
+ <li> Add __WIN32__ to Preprocessor definitions (in
1432
+ Project->$Project_Name Properties...->C/C++->Preprocessor)
1433
+ <li> Set Create/Use Precompiled Header to Not Using Precompiled Headers
1434
+ (in Project->$Project_Name Properties...->C/C++->Precompiled Headers)
1435
+ <li> Build the DLL.
1436
+ <li> You may have to rename .dll to .pyd
1437
+ </ol>
1438
+
1439
+
1440
+ <!--
1441
+ There do exist work arounds, however. In
1442
+ http://aspn.activestate.com/ASPN/Mail/Message/python-list/983252
1443
+ they presented a solution: 1) find the version of python in the
1444
+ registry 2) perform LoadLibrary("pythonxx.dll") and 3) resolve the
1445
+ reference to functions through GetProcAddress. It is said that SWIG
1446
+ may help on this.
1447
+ http://mailman.cs.uchicago.edu/pipermail/swig/2001-July/002744.html
1448
+ presented a similar example.
1449
+ -->
1450
+ <p align="right">
1451
+ <a href="#_TOP">[Go Top]</a>
1452
+ <hr/>
1453
+ <a name="/Q8:_Python_interface"></a>
1454
+ <a name="f704"><b>Q: Except the python-C++ interface provided, could I use Jython to call libsvm ?</b></a>
1455
+ <br/>
1456
+ <p> Yes, here are some examples:
1457
+
1458
+ <pre>
1459
+ $ export CLASSPATH=$CLASSPATH:~/libsvm-2.4/java/libsvm.jar
1460
+ $ ./jython
1461
+ Jython 2.1a3 on java1.3.0 (JIT: jitc)
1462
+ Type "copyright", "credits" or "license" for more information.
1463
+ >>> from libsvm import *
1464
+ >>> dir()
1465
+ ['__doc__', '__name__', 'svm', 'svm_model', 'svm_node', 'svm_parameter',
1466
+ 'svm_problem']
1467
+ >>> x1 = [svm_node(index=1,value=1)]
1468
+ >>> x2 = [svm_node(index=1,value=-1)]
1469
+ >>> param = svm_parameter(svm_type=0,kernel_type=2,gamma=1,cache_size=40,eps=0.001,C=1,nr_weight=0,shrinking=1)
1470
+ >>> prob = svm_problem(l=2,y=[1,-1],x=[x1,x2])
1471
+ >>> model = svm.svm_train(prob,param)
1472
+ *
1473
+ optimization finished, #iter = 1
1474
+ nu = 1.0
1475
+ obj = -1.018315639346838, rho = 0.0
1476
+ nSV = 2, nBSV = 2
1477
+ Total nSV = 2
1478
+ >>> svm.svm_predict(model,x1)
1479
+ 1.0
1480
+ >>> svm.svm_predict(model,x2)
1481
+ -1.0
1482
+ >>> svm.svm_save_model("test.model",model)
1483
+
1484
+ </pre>
1485
+
1486
+ <p align="right">
1487
+ <a href="#_TOP">[Go Top]</a>
1488
+ <hr/>
1489
+ <a name="/Q8:_Python_interface"></a>
1490
+ <a name="f705"><b>Q: How could I install the python interface on Mac OS? </b></a>
1491
+ <br/>
1492
+ <p> Instead of
1493
+ LDFLAGS = -shared
1494
+ in the Makefile, you need
1495
+ <pre>
1496
+ LDFLAGS = -framework Python -bundle
1497
+ </pre>
1498
+ <!--
1499
+ LDFLAGS = -bundle -flat_namespace -undefined suppress
1500
+ -->
1501
+
1502
+ The problem is that under MacOs there is no "shared libraries."
1503
+ Instead they use "dynamic libraries."
1504
+ <p align="right">
1505
+ <a href="#_TOP">[Go Top]</a>
1506
+ <hr/>
1507
+ <a name="/Q8:_Python_interface"></a>
1508
+ <a name="f706"><b>Q: I typed "make" on a unix system, but it says "Python.h: No such file or directory?"</b></a>
1509
+ <br/>
1510
+ <p>
1511
+ Even though you may have python on your
1512
+ system, very likely
1513
+ python development tools
1514
+ are not installed. Please check with
1515
+ your system administrator.
1516
+ <p align="right">
1517
+ <a href="#_TOP">[Go Top]</a>
1518
+ <hr/>
1519
+ <a name="/Q9:_MATLAB_interface"></a>
1520
+ <a name="f801"><b>Q: I compile the MATLAB interface without problem, but why errors occur while running it?</b></a>
1521
+ <br/>
1522
+ <p>
1523
+ Your compiler version may not be supported/compatible for MATLAB.
1524
+ Please check <a href=http://www.mathworks.com/support/compilers/current_release>this MATLAB page</a> first and then specify the version
1525
+ number. For example, if g++ X.Y is supported, replace
1526
+ <pre>
1527
+ CXX = g++
1528
+ </pre>
1529
+ in the Makefile with
1530
+ <pre>
1531
+ CXX = g++-X.Y
1532
+ </pre>
1533
+ <p align="right">
1534
+ <a href="#_TOP">[Go Top]</a>
1535
+ <hr/>
1536
+ <a name="/Q9:_MATLAB_interface"></a>
1537
+ <a name="f8011"><b>Q: On 64bit Windows I compile the MATLAB interface without problem, but why errors occur while running it?</b></a>
1538
+ <br/>
1539
+ <p>
1540
+
1541
+
1542
+ Please make sure that you have modified make.m
1543
+ to use -largeArrayDims option. For example,
1544
+ <pre>
1545
+ mex -largeArrayDims -O -c svm.cpp
1546
+ </pre>
1547
+
1548
+ Moreover, if you use Microsoft Visual Studio,
1549
+ probabally it is not properly installed.
1550
+ See the explanation
1551
+ <a href=http://www.mathworks.com/support/compilers/current_release/win64.html#n7>here</a>.
1552
+ <p align="right">
1553
+ <a href="#_TOP">[Go Top]</a>
1554
+ <hr/>
1555
+ <a name="/Q9:_MATLAB_interface"></a>
1556
+ <a name="f802"><b>Q: Does the MATLAB interface provide a function to do scaling?</b></a>
1557
+ <br/>
1558
+ <p>
1559
+ It is extremely easy to do scaling under MATLAB.
1560
+ The following one-line code scale each feature to the range
1561
+ of [0.1]:
1562
+ <pre>
1563
+ (data - repmat(min(data,[],1),size(data,1),1))*spdiags(1./(max(data,[],1)-min(data,[],1))',0,size(data,2),size(data,2))
1564
+ </pre>
1565
+ <p align="right">
1566
+ <a href="#_TOP">[Go Top]</a>
1567
+ <hr/>
1568
+ <a name="/Q9:_MATLAB_interface"></a>
1569
+ <a name="f803"><b>Q: How could I use MATLAB interface for parameter selection?</b></a>
1570
+ <br/>
1571
+ <p>
1572
+ One can do this by a simple loop.
1573
+ See the following example:
1574
+ <pre>
1575
+ bestcv = 0;
1576
+ for log2c = -1:3,
1577
+ for log2g = -4:1,
1578
+ cmd = ['-v 5 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
1579
+ cv = svmtrain(heart_scale_label, heart_scale_inst, cmd);
1580
+ if (cv >= bestcv),
1581
+ bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
1582
+ end
1583
+ fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
1584
+ end
1585
+ end
1586
+ </pre>
1587
+ You may adjust the parameter range in the above loops.
1588
+ <p align="right">
1589
+ <a href="#_TOP">[Go Top]</a>
1590
+ <hr/>
1591
+ <a name="/Q9:_MATLAB_interface"></a>
1592
+ <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>
1593
+ <br/>
1594
+ <p>
1595
+ Fabrizio Lacalandra of University of Pisa reported this issue.
1596
+ It seems the problem is caused by the screen output.
1597
+ If you disable the <b>info</b> function
1598
+ using <pre>#if 0,</pre> then the problem
1599
+ may be solved.
1600
+ <p align="right">
1601
+ <a href="#_TOP">[Go Top]</a>
1602
+ <hr/>
1603
+ <a name="/Q9:_MATLAB_interface"></a>
1604
+ <a name="f8032"><b>Q: How do I use LIBSVM with OpenMP under MATLAB?</b></a>
1605
+ <br/>
1606
+ <p>
1607
+ In Makefile,
1608
+ you need to add -fopenmp to CFLAGS and -lgomp to MEX_OPTION. For Octave, you need the same modification.
1609
+
1610
+ <p> However, a minor problem is that
1611
+ the number of threads cannot
1612
+ be specified in MATLAB. We tried Version 7.7 (R2008b) and gcc-4.3.3.
1613
+
1614
+ <pre>
1615
+ % export OMP_NUM_THREADS=4; matlab
1616
+ >> setenv('OMP_NUM_THREADS', '1');
1617
+ </pre>
1618
+
1619
+ Then OMP_NUM_THREADS is still 4 while running the program. Please contact us if you
1620
+ see how to solve this problem.
1621
+ <p align="right">
1622
+ <a href="#_TOP">[Go Top]</a>
1623
+ <hr/>
1624
+ <a name="/Q9:_MATLAB_interface"></a>
1625
+ <a name="f804"><b>Q: How could I generate the primal variable w of linear SVM?</b></a>
1626
+ <br/>
1627
+ <p>
1628
+ Let's start from the binary class and
1629
+ assume you have two labels -1 and +1.
1630
+ After obtaining the model from calling svmtrain,
1631
+ do the following to have w and b:
1632
+ <pre>
1633
+ w = model.SVs' * model.sv_coef;
1634
+ b = -model.rho;
1635
+
1636
+ if model.Label(1) == -1
1637
+ w = -w;
1638
+ b = -b;
1639
+ end
1640
+ </pre>
1641
+ If you do regression or one-class SVM, then the if statement is not needed.
1642
+
1643
+ <p> For multi-class SVM, we illustrate the setting
1644
+ in the following example of running the iris
1645
+ data, which have 3 classes
1646
+ <pre>
1647
+ > [y, x] = libsvmread('../../htdocs/libsvmtools/datasets/multiclass/iris.scale');
1648
+ > m = svmtrain(y, x, '-t 0')
1649
+
1650
+ m =
1651
+
1652
+ Parameters: [5x1 double]
1653
+ nr_class: 3
1654
+ totalSV: 42
1655
+ rho: [3x1 double]
1656
+ Label: [3x1 double]
1657
+ ProbA: []
1658
+ ProbB: []
1659
+ nSV: [3x1 double]
1660
+ sv_coef: [42x2 double]
1661
+ SVs: [42x4 double]
1662
+ </pre>
1663
+ sv_coef is like:
1664
+ <pre>
1665
+ +-+-+--------------------+
1666
+ |1|1| |
1667
+ |v|v| SVs from class 1 |
1668
+ |2|3| |
1669
+ +-+-+--------------------+
1670
+ |1|2| |
1671
+ |v|v| SVs from class 2 |
1672
+ |2|3| |
1673
+ +-+-+--------------------+
1674
+ |1|2| |
1675
+ |v|v| SVs from class 3 |
1676
+ |3|3| |
1677
+ +-+-+--------------------+
1678
+ </pre>
1679
+ so we need to see nSV of each classes.
1680
+ <pre>
1681
+ > m.nSV
1682
+
1683
+ ans =
1684
+
1685
+ 3
1686
+ 21
1687
+ 18
1688
+ </pre>
1689
+ Suppose the goal is to find the vector w of classes
1690
+ 1 vs 3. Then
1691
+ y_i alpha_i of training 1 vs 3 are
1692
+ <pre>
1693
+ > coef = [m.sv_coef(1:3,2); m.sv_coef(25:42,1)];
1694
+ </pre>
1695
+ and SVs are:
1696
+ <pre>
1697
+ > SVs = [m.SVs(1:3,:); m.SVs(25:42,:)];
1698
+ </pre>
1699
+ Hence, w is
1700
+ <pre>
1701
+ > w = SVs'*coef;
1702
+ </pre>
1703
+ For rho,
1704
+ <pre>
1705
+ > m.rho
1706
+
1707
+ ans =
1708
+
1709
+ 1.1465
1710
+ 0.3682
1711
+ -1.9969
1712
+ > b = -m.rho(2);
1713
+ </pre>
1714
+ because rho is arranged by 1vs2 1vs3 2vs3.
1715
+
1716
+
1717
+
1718
+ <p align="right">
1719
+ <a href="#_TOP">[Go Top]</a>
1720
+ <hr/>
1721
+ <a name="/Q9:_MATLAB_interface"></a>
1722
+ <a name="f805"><b>Q: Is there an OCTAVE interface for libsvm?</b></a>
1723
+ <br/>
1724
+ <p>
1725
+ Yes, after libsvm 2.86, the matlab interface
1726
+ works on OCTAVE as well. Please type
1727
+ <pre>
1728
+ make octave
1729
+ </pre>
1730
+ for installation.
1731
+ <p align="right">
1732
+ <a href="#_TOP">[Go Top]</a>
1733
+ <hr/>
1734
+ <a name="/Q9:_MATLAB_interface"></a>
1735
+ <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>
1736
+ <br/>
1737
+ <p>
1738
+ The easiest way is to rename the svmtrain binary
1739
+ file (e.g., svmtrain.mexw32 on 32-bit windows)
1740
+ to a different
1741
+ name (e.g., svmtrain2.mexw32).
1742
+ <p align="right">
1743
+ <a href="#_TOP">[Go Top]</a>
1744
+ <hr/>
1745
+ <p align="middle">
1746
+ <a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm">LIBSVM home page</a>
1747
+ </p>
1748
+ </body>
1749
+ </html>