svm_toolkit 1.1.7-java → 1.1.8-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.rdoc +59 -59
- data/README.rdoc +99 -103
- data/bin/svm-demo +354 -354
- data/lib/libsvm.jar +0 -0
- data/lib/svm_toolkit/evaluators.rb +169 -169
- data/lib/svm_toolkit/model.rb +122 -124
- data/lib/svm_toolkit/node.rb +17 -21
- data/lib/svm_toolkit/parameter.rb +114 -117
- data/lib/svm_toolkit/problem.rb +294 -308
- data/lib/svm_toolkit/svm.rb +219 -224
- data/lib/svm_toolkit.rb +37 -37
- metadata +26 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af7505fa58e29043cb54b75ead159862ff156a6ab7cb2c4f96c9b10ede718ce5
|
|
4
|
+
data.tar.gz: c5cae68444d0fd9d8427853935486370099c352c3e8162deaf457b7d1071ce94
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 89e2cc63ad0840b73e70b8918f2692314698dbd2ec192ac824d7596f98d1c3f81d50b0c0f460bf01cae4ca52191029cd6d5d5440c110004727222ed3a713ef8d
|
|
7
|
+
data.tar.gz: 942e0aff5614cdbd7eaa19af61491d3c9dff87edcb08ab356460d352d1e12ea7b545444617a588ea1d7ced2c920b1c11202460bc95e70ea91e6b38f8dfa0c385
|
data/LICENSE.rdoc
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
= MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2011-20, Peter Lane
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
= For libsvm:
|
|
25
|
-
|
|
26
|
-
Copyright (c) 2000-2012 Chih-Chung Chang and Chih-Jen Lin
|
|
27
|
-
All rights reserved.
|
|
28
|
-
|
|
29
|
-
Redistribution and use in source and binary forms, with or without
|
|
30
|
-
modification, are permitted provided that the following conditions
|
|
31
|
-
are met:
|
|
32
|
-
|
|
33
|
-
1. Redistributions of source code must retain the above copyright
|
|
34
|
-
notice, this list of conditions and the following disclaimer.
|
|
35
|
-
|
|
36
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
37
|
-
notice, this list of conditions and the following disclaimer in the
|
|
38
|
-
documentation and/or other materials provided with the distribution.
|
|
39
|
-
|
|
40
|
-
3. Neither name of copyright holders nor the names of its contributors
|
|
41
|
-
may be used to endorse or promote products derived from this software
|
|
42
|
-
without specific prior written permission.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
46
|
-
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
47
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
48
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
|
|
49
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
50
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
51
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
52
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
53
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
54
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
55
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
56
|
-
|
|
57
|
-
= For PlotPackage:
|
|
58
|
-
|
|
59
|
-
Library General Public License (http://www.gnu.org/copyleft/lgpl.html)
|
|
1
|
+
= MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2011-20, Peter Lane
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
= For libsvm:
|
|
25
|
+
|
|
26
|
+
Copyright (c) 2000-2012 Chih-Chung Chang and Chih-Jen Lin
|
|
27
|
+
All rights reserved.
|
|
28
|
+
|
|
29
|
+
Redistribution and use in source and binary forms, with or without
|
|
30
|
+
modification, are permitted provided that the following conditions
|
|
31
|
+
are met:
|
|
32
|
+
|
|
33
|
+
1. Redistributions of source code must retain the above copyright
|
|
34
|
+
notice, this list of conditions and the following disclaimer.
|
|
35
|
+
|
|
36
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
37
|
+
notice, this list of conditions and the following disclaimer in the
|
|
38
|
+
documentation and/or other materials provided with the distribution.
|
|
39
|
+
|
|
40
|
+
3. Neither name of copyright holders nor the names of its contributors
|
|
41
|
+
may be used to endorse or promote products derived from this software
|
|
42
|
+
without specific prior written permission.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
46
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
47
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
48
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
|
|
49
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
50
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
51
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
52
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
53
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
54
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
55
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
56
|
+
|
|
57
|
+
= For PlotPackage:
|
|
58
|
+
|
|
59
|
+
Library General Public License (http://www.gnu.org/copyleft/lgpl.html)
|
data/README.rdoc
CHANGED
|
@@ -1,103 +1,99 @@
|
|
|
1
|
-
= SVM Toolkit
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
#
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
#
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[0.5,
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
[1.0,0.
|
|
58
|
-
[0.
|
|
59
|
-
[0.
|
|
60
|
-
[0.
|
|
61
|
-
[1.0,0.5,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
#
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
# -- test kernel performance on the
|
|
86
|
-
errors = model.evaluate_dataset(
|
|
87
|
-
puts "Kernel #{Parameter.kernel_name(kernel)} has #{errors} on the
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
The contour plot uses the PlotPackage library, available from:
|
|
102
|
-
http://thehuwaldtfamily.org/java/Packages/Plot/PlotPackage.html
|
|
103
|
-
|
|
1
|
+
= SVM Toolkit
|
|
2
|
+
|
|
3
|
+
Support-vector machines are a popular tool in data mining. This package
|
|
4
|
+
includes an amended version of the Java implementation of the libsvm library
|
|
5
|
+
(version 3.11). Additional methods and examples are provided to support
|
|
6
|
+
standard training techniques, such as cross-validation, and simple
|
|
7
|
+
visualisations. Training/testing of models can use a variety of built-in or
|
|
8
|
+
user-defined evaluation methods, including overall accuracy, geometric mean,
|
|
9
|
+
precision and recall.
|
|
10
|
+
|
|
11
|
+
== Features
|
|
12
|
+
|
|
13
|
+
- All features of LibSVM 3.11 are supported, and many are augmented with Ruby wrappers.
|
|
14
|
+
- Loading Problem definitions from file in Svmlight, Csv or Arff (simple subset) format.
|
|
15
|
+
- Creating Problem definitions from values supplied programmatically in arrays.
|
|
16
|
+
- Rescaling of feature values.
|
|
17
|
+
- Integrated cost/gamma search for model with RBF kernel, taking advantage of multiple cores.
|
|
18
|
+
- Contour plot visualisation of cost/gamma search results.
|
|
19
|
+
- Model provides value of w-squared for hyperplane.
|
|
20
|
+
- svm-demo application, a version of the svm_toy applet which comes with libsvm.
|
|
21
|
+
- Model stores indices of training instances used as support vectors.
|
|
22
|
+
- User-selected evaluation techniques supported in Model#evaluate_dataset and
|
|
23
|
+
Svm.cross_validation_search.
|
|
24
|
+
- Library provides evaluation classes for Cohen's Kappa statistics, F-measure,
|
|
25
|
+
geometric-mean, Matthews Correlation Coefficient, overall-accuracy,
|
|
26
|
+
precision, and recall.
|
|
27
|
+
|
|
28
|
+
== Example
|
|
29
|
+
|
|
30
|
+
The following example illustrates how a dataset can be constructed in code, and
|
|
31
|
+
an SVM model created and tested against the different kernels.
|
|
32
|
+
|
|
33
|
+
require "svm_toolkit"
|
|
34
|
+
include SvmToolkit
|
|
35
|
+
|
|
36
|
+
puts "Classification with LIBSVM"
|
|
37
|
+
puts "--------------------------"
|
|
38
|
+
|
|
39
|
+
# Sample dataset: the 'Play Tennis' dataset
|
|
40
|
+
# from T. Mitchell, Machine Learning (1997)
|
|
41
|
+
# --------------------------------------------
|
|
42
|
+
# Labels for each instance in the training set
|
|
43
|
+
# 1 = Play, 0 = Not
|
|
44
|
+
Labels = [0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0]
|
|
45
|
+
|
|
46
|
+
# Recoding the attribute values into range [0, 1]
|
|
47
|
+
Instances = [
|
|
48
|
+
[0.0,1.0,1.0,0.0],
|
|
49
|
+
[0.0,1.0,1.0,1.0],
|
|
50
|
+
[0.5,1.0,1.0,0.0],
|
|
51
|
+
[1.0,0.5,1.0,0.0],
|
|
52
|
+
[1.0,0.0,0.0,0.0],
|
|
53
|
+
[1.0,0.0,0.0,1.0],
|
|
54
|
+
[0.5,0.0,0.0,1.0],
|
|
55
|
+
[0.0,0.5,1.0,0.0],
|
|
56
|
+
[0.0,0.0,0.0,0.0],
|
|
57
|
+
[1.0,0.5,0.0,0.0],
|
|
58
|
+
[0.0,0.5,0.0,1.0],
|
|
59
|
+
[0.5,0.5,1.0,1.0],
|
|
60
|
+
[0.5,1.0,0.0,0.0],
|
|
61
|
+
[1.0,0.5,1.0,1.0]
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
# create some arbitrary train/test split
|
|
65
|
+
TrainingSet = Problem.from_array(Instances.slice(0, 10), Labels.slice(0, 10))
|
|
66
|
+
TestSet = Problem.from_array(Instances.slice(10, 4), Labels.slice(10, 4))
|
|
67
|
+
|
|
68
|
+
# Iterate over each kernel type
|
|
69
|
+
Parameter.kernels.each do |kernel|
|
|
70
|
+
|
|
71
|
+
# -- train model for this kernel type
|
|
72
|
+
params = Parameter.new(
|
|
73
|
+
:svm_type => Parameter::C_SVC,
|
|
74
|
+
:kernel_type => kernel,
|
|
75
|
+
:cost => 10,
|
|
76
|
+
:degree => 1,
|
|
77
|
+
:gamma => 100
|
|
78
|
+
)
|
|
79
|
+
model = Svm.svm_train(TrainingSet, params)
|
|
80
|
+
|
|
81
|
+
# -- test kernel performance on the training set
|
|
82
|
+
errors = model.evaluate_dataset(TrainingSet, :print_results => true)
|
|
83
|
+
puts "Kernel #{Parameter.kernel_name(kernel)} has #{errors} on the training set"
|
|
84
|
+
|
|
85
|
+
# -- test kernel performance on the test set
|
|
86
|
+
errors = model.evaluate_dataset(TestSet, :print_results => true)
|
|
87
|
+
puts "Kernel #{Parameter.kernel_name(kernel)} has #{errors} on the test set"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
More examples can be found in the source: https://codeberg.org/peterlane/svm_toolkit
|
|
91
|
+
|
|
92
|
+
== Acknowledgements
|
|
93
|
+
|
|
94
|
+
The svm_toolkit is based on LibSVM, which is available from:
|
|
95
|
+
http://www.csie.ntu.edu.tw/~cjlin/libsvm/
|
|
96
|
+
|
|
97
|
+
The contour plot uses the PlotPackage library, available from:
|
|
98
|
+
http://thehuwaldtfamily.org/java/Packages/Plot/PlotPackage.html
|
|
99
|
+
|