numo-liblinear 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 +7 -6
- data/ext/numo/liblinear/liblinearext.c +34 -2
- data/lib/numo/liblinear/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: 31b76e6a2a8dcfc5cb643fa0b62cd9ace5b6a76c
|
4
|
+
data.tar.gz: 6d8b6d9ed6a7e069ca8fcb78fb9f8999ccdfe1c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8efe216d52fc7bba1561f46c3a372e842d6bdaf371c9b71b7662e380a17e9c6396e4a67348156522a41785bf2a12f37675dd137f173a0f52b6c48528c9c70cf7
|
7
|
+
data.tar.gz: e23e845ed639ee5e7fff6cbbbe936feed71f3a7e16429c52a27872b019201818649de57576030fb996cd697ff490588a0ec8e8d1e452eb0d441baa4ea00bcf52
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](https://travis-ci.org/yoshoku/numo-liblinear)
|
4
4
|
[](https://badge.fury.io/rb/numo-liblinear)
|
5
5
|
[](https://github.com/yoshoku/numo-liblinear/blob/master/LICENSE.txt)
|
6
|
-
[](https://www.rubydoc.info/gems/numo-liblinear/0.
|
6
|
+
[](https://www.rubydoc.info/gems/numo-liblinear/0.4.0)
|
7
7
|
|
8
8
|
Numo::Liblinear is a Ruby gem binding to the [LIBLINEAR](https://www.csie.ntu.edu.tw/~cjlin/liblinear/) library.
|
9
9
|
LIBLINEAR is one of the famous libraries for large-scale regularized linear classification and regression.
|
@@ -163,13 +163,14 @@ param = {
|
|
163
163
|
solver_type: # [Integer] Type of Solver
|
164
164
|
Numo::Liblinear::SolverType::L2R_L2LOSS_SVC_DUAL,
|
165
165
|
eps: 0.01, # [Float] Stopping criterion
|
166
|
-
C: 1, # [Float] Cost of constraints violation
|
167
|
-
nr_weight: 3, # [Integer] Number of weights
|
168
|
-
weight_label: # [Numo::Int32] Labels to add weight
|
166
|
+
C: 1, # [Float] Cost of constraints violation
|
167
|
+
nr_weight: 3, # [Integer] Number of weights
|
168
|
+
weight_label: # [Numo::Int32] Labels to add weight
|
169
169
|
Numo::Int32[0, 1, 2],
|
170
|
-
weight: # [Numo::DFloat] Weight values
|
170
|
+
weight: # [Numo::DFloat] Weight values
|
171
171
|
Numo::DFloat[0.4, 0.4, 0.2],
|
172
|
-
p: 0.1, # [Float] Sensitiveness of loss of support vector regression
|
172
|
+
p: 0.1, # [Float] Sensitiveness of loss of support vector regression
|
173
|
+
verbose: false, # [Boolean] Whether to output learning process message
|
173
174
|
random_seed: 1 # [Integer/Nil] Random seed
|
174
175
|
}
|
175
176
|
```
|
@@ -53,6 +53,7 @@ VALUE numo_liblinear_train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_has
|
|
53
53
|
narray_t* y_nary;
|
54
54
|
char* err_msg;
|
55
55
|
VALUE random_seed;
|
56
|
+
VALUE verbose;
|
56
57
|
VALUE model_hash;
|
57
58
|
|
58
59
|
if (CLASS_OF(x_val) != numo_cDFloat) {
|
@@ -99,7 +100,11 @@ VALUE numo_liblinear_train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_has
|
|
99
100
|
return Qnil;
|
100
101
|
}
|
101
102
|
|
102
|
-
|
103
|
+
verbose = rb_hash_aref(param_hash, ID2SYM(rb_intern("verbose")));
|
104
|
+
if (verbose != Qtrue) {
|
105
|
+
set_print_string_function(print_null);
|
106
|
+
}
|
107
|
+
|
103
108
|
model = train(problem, param);
|
104
109
|
model_hash = model_to_rb_hash(model);
|
105
110
|
free_and_destroy_model(&model);
|
@@ -120,6 +125,28 @@ VALUE numo_liblinear_train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_has
|
|
120
125
|
* @param param [Hash] The parameters of a model.
|
121
126
|
* @param n_folds [Integer] The number of folds.
|
122
127
|
*
|
128
|
+
* @example
|
129
|
+
* require 'numo/liblinear'
|
130
|
+
*
|
131
|
+
* # x: samples
|
132
|
+
* # y: labels
|
133
|
+
*
|
134
|
+
* # Define parameters of L2-regularized L2-loss support vector classification.
|
135
|
+
* param = {
|
136
|
+
* solver_type: Numo::Liblinear::SolverType::L2R_L2LOSS_SVC_DUAL,
|
137
|
+
* C: 1,
|
138
|
+
* random_seed: 1,
|
139
|
+
* verbose: true
|
140
|
+
* }
|
141
|
+
*
|
142
|
+
* # Perform 5-cross validation.
|
143
|
+
* n_folds = 5
|
144
|
+
* res = Numo::Liblinear::cv(x, y, param, n_folds)
|
145
|
+
*
|
146
|
+
* # Print mean accuracy.
|
147
|
+
* mean_accuracy = y.eq(res).count.fdiv(y.size)
|
148
|
+
* puts "Accuracy: %.1f %%" % (100 * mean_accuracy)
|
149
|
+
*
|
123
150
|
* @raise [ArgumentError] If the sample array is not 2-dimensional, the label array is not 1-dimensional,
|
124
151
|
* the sample array and label array do not have the same number of samples, or
|
125
152
|
* the hyperparameter has an invalid value, this error is raised.
|
@@ -136,6 +163,7 @@ VALUE numo_liblinear_cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALU
|
|
136
163
|
narray_t* y_nary;
|
137
164
|
char* err_msg;
|
138
165
|
VALUE random_seed;
|
166
|
+
VALUE verbose;
|
139
167
|
struct problem* problem;
|
140
168
|
struct parameter* param;
|
141
169
|
|
@@ -187,7 +215,11 @@ VALUE numo_liblinear_cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALU
|
|
187
215
|
t_val = rb_narray_new(numo_cDFloat, 1, t_shape);
|
188
216
|
t_pt = (double*)na_get_pointer_for_write(t_val);
|
189
217
|
|
190
|
-
|
218
|
+
verbose = rb_hash_aref(param_hash, ID2SYM(rb_intern("verbose")));
|
219
|
+
if (verbose != Qtrue) {
|
220
|
+
set_print_string_function(print_null);
|
221
|
+
}
|
222
|
+
|
191
223
|
cross_validation(problem, param, n_folds, t_pt);
|
192
224
|
|
193
225
|
xfree_problem(problem);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numo-liblinear
|
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
|