numo-libsvm 0.3.0 → 0.4.0
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/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/ext/numo/libsvm/libsvmext.c +36 -2
- data/lib/numo/libsvm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '098e529149ba06f54fc8c4949afa2051dd62f856'
|
4
|
+
data.tar.gz: b86c22820135dff7f95c34dfe6517f89d451156f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d3ed02591f622d50203c6552671ebcfa26ead1cf86816e0ae166548981409ef8b6b14bce2a0123e9d3f1abcaf121b52c49e7ee4110ebc3e4a0f4224902c388a
|
7
|
+
data.tar.gz: 56595713d0dccca3f953ee7583f90ca6fb63d83eedb0d6f2878caaacf6c8db859628f82c88e95b5062eabb85316bbe034fa716b86aebd07fc5f414a5f1ccda77
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](https://travis-ci.org/yoshoku/numo-libsvm)
|
4
4
|
[](https://badge.fury.io/rb/numo-libsvm)
|
5
5
|
[](https://github.com/yoshoku/numo-libsvm/blob/master/LICENSE.txt)
|
6
|
-
[](https://www.rubydoc.info/gems/numo-libsvm/0.
|
6
|
+
[](https://www.rubydoc.info/gems/numo-libsvm/0.4.0)
|
7
7
|
|
8
8
|
Numo::Libsvm is a Ruby gem binding to the [LIBSVM](https://github.com/cjlin1/libsvm) library.
|
9
9
|
LIBSVM is one of the famous libraries that implemented Support Vector Machines,
|
@@ -190,6 +190,7 @@ param = {
|
|
190
190
|
p: 0.1, # [Float] Parameter epsilon in loss function of epsilon-SVR
|
191
191
|
shrinking: true, # [Boolean] Whether to use the shrinking heuristics
|
192
192
|
probability: false, # [Boolean] Whether to train a SVC or SVR model for probability estimates
|
193
|
+
verbose: false, # [Boolean] Whether to output learning process message
|
193
194
|
random_seed: 1 # [Integer/Nil] Random seed
|
194
195
|
}
|
195
196
|
```
|
data/ext/numo/libsvm/libsvmext.c
CHANGED
@@ -55,6 +55,7 @@ VALUE train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_hash)
|
|
55
55
|
narray_t* y_nary;
|
56
56
|
char* err_msg;
|
57
57
|
VALUE random_seed;
|
58
|
+
VALUE verbose;
|
58
59
|
VALUE model_hash;
|
59
60
|
|
60
61
|
if (CLASS_OF(x_val) != numo_cDFloat) {
|
@@ -101,7 +102,11 @@ VALUE train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_hash)
|
|
101
102
|
return Qnil;
|
102
103
|
}
|
103
104
|
|
104
|
-
|
105
|
+
verbose = rb_hash_aref(param_hash, ID2SYM(rb_intern("verbose")));
|
106
|
+
if (verbose != Qtrue) {
|
107
|
+
svm_set_print_string_function(print_null);
|
108
|
+
}
|
109
|
+
|
105
110
|
model = svm_train(problem, param);
|
106
111
|
model_hash = svm_model_to_rb_hash(model);
|
107
112
|
svm_free_and_destroy_model(&model);
|
@@ -122,6 +127,30 @@ VALUE train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_hash)
|
|
122
127
|
* @param param [Hash] The parameters of an SVM model.
|
123
128
|
* @param n_folds [Integer] The number of folds.
|
124
129
|
*
|
130
|
+
* @example
|
131
|
+
* require 'numo/libsvm'
|
132
|
+
*
|
133
|
+
* # x: samples
|
134
|
+
* # y: labels
|
135
|
+
*
|
136
|
+
* # Define parameters of C-SVC with RBF Kernel.
|
137
|
+
* param = {
|
138
|
+
* svm_type: Numo::Libsvm::SvmType::C_SVC,
|
139
|
+
* kernel_type: Numo::Libsvm::KernelType::RBF,
|
140
|
+
* gamma: 1.0,
|
141
|
+
* C: 1,
|
142
|
+
* random_seed: 1,
|
143
|
+
* verbose: true
|
144
|
+
* }
|
145
|
+
*
|
146
|
+
* # Perform 5-cross validation.
|
147
|
+
* n_folds = 5
|
148
|
+
* res = Numo::Libsvm.cv(x, y, param, n_folds)
|
149
|
+
*
|
150
|
+
* # Print mean accuracy.
|
151
|
+
* mean_accuracy = y.eq(res).count.fdiv(y.size)
|
152
|
+
* puts "Accuracy: %.1f %%" % (100 * mean_accuracy)
|
153
|
+
*
|
125
154
|
* @raise [ArgumentError] If the sample array is not 2-dimensional, the label array is not 1-dimensional,
|
126
155
|
* the sample array and label array do not have the same number of samples, or
|
127
156
|
* the hyperparameter has an invalid value, this error is raised.
|
@@ -138,6 +167,7 @@ VALUE cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALUE param_hash, V
|
|
138
167
|
narray_t* y_nary;
|
139
168
|
char* err_msg;
|
140
169
|
VALUE random_seed;
|
170
|
+
VALUE verbose;
|
141
171
|
struct svm_problem* problem;
|
142
172
|
struct svm_parameter* param;
|
143
173
|
|
@@ -189,7 +219,11 @@ VALUE cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALUE param_hash, V
|
|
189
219
|
t_val = rb_narray_new(numo_cDFloat, 1, t_shape);
|
190
220
|
t_pt = (double*)na_get_pointer_for_write(t_val);
|
191
221
|
|
192
|
-
|
222
|
+
verbose = rb_hash_aref(param_hash, ID2SYM(rb_intern("verbose")));
|
223
|
+
if (verbose != Qtrue) {
|
224
|
+
svm_set_print_string_function(print_null);
|
225
|
+
}
|
226
|
+
|
193
227
|
svm_cross_validation(problem, param, n_folds, t_pt);
|
194
228
|
|
195
229
|
xfree_svm_problem(problem);
|
data/lib/numo/libsvm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numo-libsvm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|