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
data/lib/libsvm.jar
CHANGED
|
Binary file
|
|
@@ -1,169 +1,169 @@
|
|
|
1
|
-
module SvmToolkit
|
|
2
|
-
|
|
3
|
-
# The Evaluator classes provides some classes and methods to construct
|
|
4
|
-
# classes for evaluating the performance of a model against a dataset.
|
|
5
|
-
# Different evaluators measure different kinds of performance.
|
|
6
|
-
#
|
|
7
|
-
# Evaluator classes are accessed by name, with an optional positive label name.
|
|
8
|
-
# For example:
|
|
9
|
-
#
|
|
10
|
-
# Evaluator::OverallAccuracy # => class evaluates overall accuracy
|
|
11
|
-
# Evaluator::ClassPrecision(label) # => class evaluates precision for class "label"
|
|
12
|
-
#
|
|
13
|
-
# Evaluators are wrapped around confusion matrices, outputting the required
|
|
14
|
-
# statistical measure, and support the following methods:
|
|
15
|
-
#
|
|
16
|
-
# add_result(actual, prediction):: called to add information about each instance
|
|
17
|
-
# when testing a model.
|
|
18
|
-
# value:: retrieves the appropriate measure of performance, based on the class name.
|
|
19
|
-
# to_s:: returns a string naming the evaluator and giving its value.
|
|
20
|
-
#
|
|
21
|
-
class Evaluator
|
|
22
|
-
|
|
23
|
-
# Defines an Evaluator returning the value of precision for given class
|
|
24
|
-
# label.
|
|
25
|
-
#
|
|
26
|
-
def Evaluator.ClassPrecision label
|
|
27
|
-
Class.new(Evaluator) do
|
|
28
|
-
@@label = label
|
|
29
|
-
|
|
30
|
-
# Returns the precision.
|
|
31
|
-
#
|
|
32
|
-
def value
|
|
33
|
-
@cm.precision(@@label)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def to_s # :nodoc:
|
|
37
|
-
"Precision for label #{@@label}: #{value}"
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Defines an Evaluator returning the value of recall for given class
|
|
43
|
-
# label.
|
|
44
|
-
#
|
|
45
|
-
def Evaluator.ClassRecall label
|
|
46
|
-
Class.new(Evaluator) do
|
|
47
|
-
@@label = label
|
|
48
|
-
|
|
49
|
-
def value # :nodoc:
|
|
50
|
-
@cm.recall(@@label)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def to_s # :nodoc:
|
|
54
|
-
"Recall for label #{@@label}: #{value}"
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# Defines an Evaluator returning the value of the F-measure for given class
|
|
60
|
-
# label.
|
|
61
|
-
#
|
|
62
|
-
def Evaluator.FMeasure label
|
|
63
|
-
Class.new(Evaluator) do
|
|
64
|
-
@@label = label
|
|
65
|
-
|
|
66
|
-
def value # :nodoc:
|
|
67
|
-
@cm.f_measure(@@label)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def to_s # :nodoc:
|
|
71
|
-
"F-measure for label #{@@label}: #{value}"
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# Defines an Evaluator returning the value of Cohen's Kappa statistics for
|
|
77
|
-
# given class label.
|
|
78
|
-
#
|
|
79
|
-
def Evaluator.Kappa label
|
|
80
|
-
Class.new(Evaluator) do
|
|
81
|
-
@@label = label
|
|
82
|
-
|
|
83
|
-
def value # :nodoc:
|
|
84
|
-
@cm.kappa(@@label)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def to_s # :nodoc:
|
|
88
|
-
"Kappa for label #{@@label}: #{value}"
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# Defines an Evaluator returning the value of the Matthews Correlation
|
|
94
|
-
# Coefficient for given class label.
|
|
95
|
-
#
|
|
96
|
-
def Evaluator.MatthewsCorrelationCoefficient label
|
|
97
|
-
Class.new(Evaluator) do
|
|
98
|
-
@@label = label
|
|
99
|
-
|
|
100
|
-
def value # :nodoc:
|
|
101
|
-
@cm.matthews_correlation(@@label)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def to_s # :nodoc:
|
|
105
|
-
"Matthews correlation coefficient: #{value}"
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# Creates a new Evaluator, with a confusion matrix to store results.
|
|
111
|
-
#
|
|
112
|
-
def initialize
|
|
113
|
-
@cm = ConfusionMatrix.new
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# Adds result to the underlying confusion matrix.
|
|
117
|
-
#
|
|
118
|
-
def add_result(actual, prediction)
|
|
119
|
-
@cm.add_for(actual, prediction)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# This object is better than given object, if the given object is an
|
|
123
|
-
# instance of nil, or the value of this object is better.
|
|
124
|
-
#
|
|
125
|
-
def better_than? other
|
|
126
|
-
other.nil? or self.value > other.value
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
# Prints the confusion matrix.
|
|
130
|
-
#
|
|
131
|
-
def display
|
|
132
|
-
puts @cm
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# Defines an Evaluator returning the value of overall accuracy.
|
|
137
|
-
#
|
|
138
|
-
class OverallAccuracy < Evaluator
|
|
139
|
-
# Returns the overall accuracy, as a percentage.
|
|
140
|
-
#
|
|
141
|
-
def value
|
|
142
|
-
100 * @cm.overall_accuracy
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
# Returns a string naming this evaluator and giving its value.
|
|
146
|
-
#
|
|
147
|
-
def to_s
|
|
148
|
-
"Overall accuracy: #{value}%"
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
# Defines an Evaluator returning the value of geometric mean.
|
|
153
|
-
#
|
|
154
|
-
class GeometricMean < Evaluator
|
|
155
|
-
# Returns the geometric mean.
|
|
156
|
-
#
|
|
157
|
-
def value
|
|
158
|
-
@cm.geometric_mean
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
# Returns a string naming this evaluator and giving its value.
|
|
162
|
-
#
|
|
163
|
-
def to_s
|
|
164
|
-
"Geometric mean: #{value}"
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
end
|
|
169
|
-
|
|
1
|
+
module SvmToolkit
|
|
2
|
+
|
|
3
|
+
# The Evaluator classes provides some classes and methods to construct
|
|
4
|
+
# classes for evaluating the performance of a model against a dataset.
|
|
5
|
+
# Different evaluators measure different kinds of performance.
|
|
6
|
+
#
|
|
7
|
+
# Evaluator classes are accessed by name, with an optional positive label name.
|
|
8
|
+
# For example:
|
|
9
|
+
#
|
|
10
|
+
# Evaluator::OverallAccuracy # => class evaluates overall accuracy
|
|
11
|
+
# Evaluator::ClassPrecision(label) # => class evaluates precision for class "label"
|
|
12
|
+
#
|
|
13
|
+
# Evaluators are wrapped around confusion matrices, outputting the required
|
|
14
|
+
# statistical measure, and support the following methods:
|
|
15
|
+
#
|
|
16
|
+
# add_result(actual, prediction):: called to add information about each instance
|
|
17
|
+
# when testing a model.
|
|
18
|
+
# value:: retrieves the appropriate measure of performance, based on the class name.
|
|
19
|
+
# to_s:: returns a string naming the evaluator and giving its value.
|
|
20
|
+
#
|
|
21
|
+
class Evaluator
|
|
22
|
+
|
|
23
|
+
# Defines an Evaluator returning the value of precision for given class
|
|
24
|
+
# label.
|
|
25
|
+
#
|
|
26
|
+
def Evaluator.ClassPrecision label
|
|
27
|
+
Class.new(Evaluator) do
|
|
28
|
+
@@label = label
|
|
29
|
+
|
|
30
|
+
# Returns the precision.
|
|
31
|
+
#
|
|
32
|
+
def value
|
|
33
|
+
@cm.precision(@@label)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def to_s # :nodoc:
|
|
37
|
+
"Precision for label #{@@label}: #{value}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Defines an Evaluator returning the value of recall for given class
|
|
43
|
+
# label.
|
|
44
|
+
#
|
|
45
|
+
def Evaluator.ClassRecall label
|
|
46
|
+
Class.new(Evaluator) do
|
|
47
|
+
@@label = label
|
|
48
|
+
|
|
49
|
+
def value # :nodoc:
|
|
50
|
+
@cm.recall(@@label)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def to_s # :nodoc:
|
|
54
|
+
"Recall for label #{@@label}: #{value}"
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Defines an Evaluator returning the value of the F-measure for given class
|
|
60
|
+
# label.
|
|
61
|
+
#
|
|
62
|
+
def Evaluator.FMeasure label
|
|
63
|
+
Class.new(Evaluator) do
|
|
64
|
+
@@label = label
|
|
65
|
+
|
|
66
|
+
def value # :nodoc:
|
|
67
|
+
@cm.f_measure(@@label)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def to_s # :nodoc:
|
|
71
|
+
"F-measure for label #{@@label}: #{value}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Defines an Evaluator returning the value of Cohen's Kappa statistics for
|
|
77
|
+
# given class label.
|
|
78
|
+
#
|
|
79
|
+
def Evaluator.Kappa label
|
|
80
|
+
Class.new(Evaluator) do
|
|
81
|
+
@@label = label
|
|
82
|
+
|
|
83
|
+
def value # :nodoc:
|
|
84
|
+
@cm.kappa(@@label)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def to_s # :nodoc:
|
|
88
|
+
"Kappa for label #{@@label}: #{value}"
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Defines an Evaluator returning the value of the Matthews Correlation
|
|
94
|
+
# Coefficient for given class label.
|
|
95
|
+
#
|
|
96
|
+
def Evaluator.MatthewsCorrelationCoefficient label
|
|
97
|
+
Class.new(Evaluator) do
|
|
98
|
+
@@label = label
|
|
99
|
+
|
|
100
|
+
def value # :nodoc:
|
|
101
|
+
@cm.matthews_correlation(@@label)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def to_s # :nodoc:
|
|
105
|
+
"Matthews correlation coefficient: #{value}"
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Creates a new Evaluator, with a confusion matrix to store results.
|
|
111
|
+
#
|
|
112
|
+
def initialize
|
|
113
|
+
@cm = ConfusionMatrix.new
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Adds result to the underlying confusion matrix.
|
|
117
|
+
#
|
|
118
|
+
def add_result(actual, prediction)
|
|
119
|
+
@cm.add_for(actual, prediction)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# This object is better than given object, if the given object is an
|
|
123
|
+
# instance of nil, or the value of this object is better.
|
|
124
|
+
#
|
|
125
|
+
def better_than? other
|
|
126
|
+
other.nil? or self.value > other.value
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Prints the confusion matrix.
|
|
130
|
+
#
|
|
131
|
+
def display
|
|
132
|
+
puts @cm
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Defines an Evaluator returning the value of overall accuracy.
|
|
137
|
+
#
|
|
138
|
+
class OverallAccuracy < Evaluator
|
|
139
|
+
# Returns the overall accuracy, as a percentage.
|
|
140
|
+
#
|
|
141
|
+
def value
|
|
142
|
+
100 * @cm.overall_accuracy
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Returns a string naming this evaluator and giving its value.
|
|
146
|
+
#
|
|
147
|
+
def to_s
|
|
148
|
+
"Overall accuracy: #{value}%"
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Defines an Evaluator returning the value of geometric mean.
|
|
153
|
+
#
|
|
154
|
+
class GeometricMean < Evaluator
|
|
155
|
+
# Returns the geometric mean.
|
|
156
|
+
#
|
|
157
|
+
def value
|
|
158
|
+
@cm.geometric_mean
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Returns a string naming this evaluator and giving its value.
|
|
162
|
+
#
|
|
163
|
+
def to_s
|
|
164
|
+
"Geometric mean: #{value}"
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
end
|
|
169
|
+
|
data/lib/svm_toolkit/model.rb
CHANGED
|
@@ -1,124 +1,122 @@
|
|
|
1
|
-
module SvmToolkit
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
#
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
#
|
|
107
|
-
#
|
|
108
|
-
#
|
|
109
|
-
#
|
|
110
|
-
#
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
dist
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return dist
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
end
|
|
124
|
-
|
|
1
|
+
module SvmToolkit
|
|
2
|
+
|
|
3
|
+
# Holds information for a trained SVM model.
|
|
4
|
+
class Model
|
|
5
|
+
|
|
6
|
+
# Evaluate model on given data set (an instance of Problem),
|
|
7
|
+
# returning the number of errors made.
|
|
8
|
+
# Optional parameters include:
|
|
9
|
+
# * :evaluator => Evaluator::OverallAccuracy, the name of the class to use for computing performance
|
|
10
|
+
# * :print_results => false, whether to print the result for each instance
|
|
11
|
+
def evaluate_dataset(data, params = {})
|
|
12
|
+
evaluator = params.fetch(:evaluator, Evaluator::OverallAccuracy)
|
|
13
|
+
print_results = params.fetch(:print_results, false)
|
|
14
|
+
performance = evaluator.new
|
|
15
|
+
data.l.times do |i|
|
|
16
|
+
pred = Svm.svm_predict(self, data.x[i])
|
|
17
|
+
performance.add_result(data.y[i], pred)
|
|
18
|
+
if print_results
|
|
19
|
+
puts "Instance #{i}, Prediction: #{pred}, True label: #{data.y[i]}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
return performance
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Return the value of w squared for the hyperplane.
|
|
26
|
+
# -- returned as an array if there is not just one value.
|
|
27
|
+
def w_squared
|
|
28
|
+
if self.w_2.size == 1
|
|
29
|
+
self.w_2[0]
|
|
30
|
+
else
|
|
31
|
+
self.w_2.to_a
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Return an array of indices of the training instances used as
|
|
36
|
+
# support vectors.
|
|
37
|
+
def support_vector_indices
|
|
38
|
+
result = []
|
|
39
|
+
unless sv_indices.nil?
|
|
40
|
+
sv_indices.size.times do |i|
|
|
41
|
+
result << sv_indices[i]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
return result
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Return the SVM problem type for this model
|
|
49
|
+
def svm_type
|
|
50
|
+
self.param.svm_type
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Return the kernel type for this model
|
|
54
|
+
def kernel_type
|
|
55
|
+
self.param.kernel_type
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Return the value of the degree parameter
|
|
59
|
+
def degree
|
|
60
|
+
self.param.degree
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Return the value of the gamma parameter
|
|
64
|
+
def gamma
|
|
65
|
+
self.param.gamma
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Return the value of the cost parameter
|
|
69
|
+
def cost
|
|
70
|
+
self.param.cost
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Return the number of classes handled by this model.
|
|
74
|
+
def number_classes
|
|
75
|
+
self.nr_class
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Save model to given filename.
|
|
79
|
+
# Raises IOError on any error.
|
|
80
|
+
def save filename
|
|
81
|
+
begin
|
|
82
|
+
Svm.svm_save_model(filename, self)
|
|
83
|
+
rescue java.io.IOException
|
|
84
|
+
raise IOError.new "Error in saving SVM model to file"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Load model from given filename.
|
|
89
|
+
# Raises IOError on any error.
|
|
90
|
+
def self.load filename
|
|
91
|
+
begin
|
|
92
|
+
Svm.svm_load_model(filename)
|
|
93
|
+
rescue java.io.IOException
|
|
94
|
+
raise IOError.new "Error in loading SVM model from file"
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
#
|
|
99
|
+
# Predict the class of given instance number in given problem.
|
|
100
|
+
#
|
|
101
|
+
def predict(problem, instance_number)
|
|
102
|
+
Svm.svm_predict(self, problem.x[instance_number])
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Return the values of given instance number of given problem against
|
|
106
|
+
# each decision boundary.
|
|
107
|
+
# (This is the distance of the instance from each boundary.)
|
|
108
|
+
#
|
|
109
|
+
# Return value is an array if more than one decision boundary.
|
|
110
|
+
#
|
|
111
|
+
def predict_values(problem, instance_number)
|
|
112
|
+
dist = Array.new(number_classes*(number_classes-1)/2, 0).to_java(:double)
|
|
113
|
+
Svm.svm_predict_values(self, problem.x[instance_number], dist)
|
|
114
|
+
if dist.size == 1
|
|
115
|
+
return dist[0]
|
|
116
|
+
else
|
|
117
|
+
return dist.to_a
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
data/lib/svm_toolkit/node.rb
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
module SvmToolkit
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
end
|
|
21
|
-
|
|
1
|
+
module SvmToolkit
|
|
2
|
+
|
|
3
|
+
# Used to store the index/value pair for an individual
|
|
4
|
+
# feature of an instance.
|
|
5
|
+
class Node
|
|
6
|
+
|
|
7
|
+
# Constructor accepts index and value of this node
|
|
8
|
+
# in feature set.
|
|
9
|
+
def initialize(index, value)
|
|
10
|
+
super()
|
|
11
|
+
self.index = index
|
|
12
|
+
self.value = value
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|