numo-liblinear 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +22 -1
- data/ext/numo/liblinear/liblinearext.c +34 -0
- 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: 0ae7bd5566c47d6b045d596945bf7b4b84955b22
|
4
|
+
data.tar.gz: 13dc445acfcf11c6097dedbbf25544f19810cb60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dac8c681d092896a0d1947ed3374d4400ea224c3bc18c4fd2ebfa65aa504181e7c01f3ffb68452d92bb22bbe54fc61e831b9bc7197da26cf3908df8b59d9fc3
|
7
|
+
data.tar.gz: 9b2a82a5a087a1f86113c10be3a11880b03357bb9e3b91191291f2824e26c672c542a7401a69638aefc3ef36a7bcee51bbdfcebad010f0f50c66460aa5e99fac
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# 0.3.0
|
2
|
+
- Add random_seed parameter for specifying seed to give to srand function.
|
3
|
+
- Several documentation improvements.
|
4
|
+
|
1
5
|
# 0.2.0
|
2
|
-
- Add
|
6
|
+
- Add validation of method parameters.
|
3
7
|
- Several documentation improvements.
|
4
8
|
|
5
9
|
# 0.1.0
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/yoshoku/numo-liblinear.svg?branch=master)](https://travis-ci.org/yoshoku/numo-liblinear)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/numo-liblinear.svg)](https://badge.fury.io/rb/numo-liblinear)
|
5
5
|
[![BSD 3-Clause License](https://img.shields.io/badge/License-BSD%203--Clause-orange.svg)](https://github.com/yoshoku/numo-liblinear/blob/master/LICENSE.txt)
|
6
|
-
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/gems/numo-liblinear/0.
|
6
|
+
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/gems/numo-liblinear/0.3.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.
|
@@ -153,6 +153,27 @@ Predict labels.
|
|
153
153
|
Accuracy: 87.9 %
|
154
154
|
```
|
155
155
|
|
156
|
+
## Note
|
157
|
+
The hyperparemter of LIBLINEAR is given with Ruby Hash on Numo::Liblinear.
|
158
|
+
The hash key of hyperparameter and its meaning match the struct parameter of LIBLINEAR.
|
159
|
+
The parameter is detailed in [LIBLINEAR README](https://github.com/cjlin1/liblinear/blob/master/README)
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
param = {
|
163
|
+
solver_type: # [Integer] Type of Solver
|
164
|
+
Numo::Liblinear::SolverType::L2R_L2LOSS_SVC_DUAL,
|
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.
|
169
|
+
Numo::Int32[0, 1, 2],
|
170
|
+
weight: # [Numo::DFloat] Weight values.
|
171
|
+
Numo::DFloat[0.4, 0.4, 0.2],
|
172
|
+
p: 0.1, # [Float] Sensitiveness of loss of support vector regression.
|
173
|
+
random_seed: 1 # [Integer/Nil] Random seed
|
174
|
+
}
|
175
|
+
```
|
176
|
+
|
156
177
|
## Development
|
157
178
|
|
158
179
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -16,6 +16,28 @@ void print_null(const char *s) {}
|
|
16
16
|
* @param y [Numo::DFloat] (shape: [n_samples]) The labels or target values for samples.
|
17
17
|
* @param param [Hash] The parameters of a model.
|
18
18
|
*
|
19
|
+
* @example
|
20
|
+
* require 'numo/liblinear'
|
21
|
+
*
|
22
|
+
* # Prepare training dataset.
|
23
|
+
* x = Numo::DFloat[[-0.8, 1.0], [-0.5, 0.8], [0.9, -0.8], [0.8, -0.7]]
|
24
|
+
* y = Numo::Int32[-1, -1, 1, 1]
|
25
|
+
*
|
26
|
+
* # Train L2-regularized L2-loss support vector classifier.
|
27
|
+
* param = {
|
28
|
+
* solver_type: Numo::Liblinear::SolverType::L2R_L2LOSS_SVC_DUAL,
|
29
|
+
* C: 0.1,
|
30
|
+
* random_seed: 1
|
31
|
+
* }
|
32
|
+
* model = Numo::Liblinear.train(x, y, param)
|
33
|
+
*
|
34
|
+
* # Predict labels of test data.
|
35
|
+
* x_test = Numo::DFloat[[-0.7, 0.9], [0.5, -0.4]]
|
36
|
+
* result = Numo::Liblinear.predict(x_test, param, model)
|
37
|
+
* p result
|
38
|
+
* # Numo::DFloat#shape=[2]
|
39
|
+
* # [-1, 1]
|
40
|
+
*
|
19
41
|
* @raise [ArgumentError] If the sample array is not 2-dimensional, the label array is not 1-dimensional,
|
20
42
|
* the sample array and label array do not have the same number of samples, or
|
21
43
|
* the hyperparameter has an invalid value, this error is raised.
|
@@ -30,6 +52,7 @@ VALUE numo_liblinear_train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_has
|
|
30
52
|
narray_t* x_nary;
|
31
53
|
narray_t* y_nary;
|
32
54
|
char* err_msg;
|
55
|
+
VALUE random_seed;
|
33
56
|
VALUE model_hash;
|
34
57
|
|
35
58
|
if (CLASS_OF(x_val) != numo_cDFloat) {
|
@@ -60,6 +83,11 @@ VALUE numo_liblinear_train(VALUE self, VALUE x_val, VALUE y_val, VALUE param_has
|
|
60
83
|
return Qnil;
|
61
84
|
}
|
62
85
|
|
86
|
+
random_seed = rb_hash_aref(param_hash, ID2SYM(rb_intern("random_seed")));
|
87
|
+
if (!NIL_P(random_seed)) {
|
88
|
+
srand(NUM2UINT(random_seed));
|
89
|
+
}
|
90
|
+
|
63
91
|
param = rb_hash_to_parameter(param_hash);
|
64
92
|
problem = dataset_to_problem(x_val, y_val);
|
65
93
|
|
@@ -107,6 +135,7 @@ VALUE numo_liblinear_cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALU
|
|
107
135
|
narray_t* x_nary;
|
108
136
|
narray_t* y_nary;
|
109
137
|
char* err_msg;
|
138
|
+
VALUE random_seed;
|
110
139
|
struct problem* problem;
|
111
140
|
struct parameter* param;
|
112
141
|
|
@@ -138,6 +167,11 @@ VALUE numo_liblinear_cross_validation(VALUE self, VALUE x_val, VALUE y_val, VALU
|
|
138
167
|
return Qnil;
|
139
168
|
}
|
140
169
|
|
170
|
+
random_seed = rb_hash_aref(param_hash, ID2SYM(rb_intern("random_seed")));
|
171
|
+
if (!NIL_P(random_seed)) {
|
172
|
+
srand(NUM2UINT(random_seed));
|
173
|
+
}
|
174
|
+
|
141
175
|
param = rb_hash_to_parameter(param_hash);
|
142
176
|
problem = dataset_to_problem(x_val, y_val);
|
143
177
|
|
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.3.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-08-
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|