liblinear-ruby 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/ext/liblinear.i +17 -0
- data/ext/liblinear_wrap.cxx +93 -0
- data/lib/liblinear.rb +8 -0
- data/lib/liblinear/version.rb +1 -1
- data/spec/liblinear/model_spec.rb +1 -0
- data/spec/liblinear_spec.rb +1 -0
- metadata +3 -5
- data/spec/liblinear/cross_validator_spec.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30ae94e9df20dcf3cc8cb98ca9aaeff3afda748f
|
4
|
+
data.tar.gz: ec8e813c7fa4f3a33038d1a1b11e637adc2cd115
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40c2879b5c2c4d0e8fb674d7b30462bdeb64ca40c5c7abc83d5be765398748905de6e1ba1f5f14c4b4c59b886ac0f6b8e827ccdb73b16302b0605e60cc36186f
|
7
|
+
data.tar.gz: a2d726b56e487a894d88f63de52b6026eaadaeafd4db91b7f2854de7623becf079e4262db5f9ab2ee2a5834ac0a4f81439604962d0aef0e07dd65939d9912623
|
data/README.md
CHANGED
@@ -123,6 +123,13 @@ If you have already had a model file, you can load it as:
|
|
123
123
|
model = Liblinear::Model.load(file_name)
|
124
124
|
```
|
125
125
|
|
126
|
+
## Feature Weights
|
127
|
+
To get the feature weights of the model.
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
model.feature_weights
|
131
|
+
```
|
132
|
+
|
126
133
|
## Predict
|
127
134
|
Prepare the data you want to predict its class and call `Liblinear.predict`.
|
128
135
|
|
@@ -138,6 +145,16 @@ For example, `results[0]` is a class predicted by `examples` excepts part includ
|
|
138
145
|
results = Liblinear.cross_validation(fold, parameter, labels, examples)
|
139
146
|
```
|
140
147
|
|
148
|
+
## Quiet / Verbose Mode
|
149
|
+
You can supress output while executing `Liblinear::Model.train`.
|
150
|
+
```ruby
|
151
|
+
# Output is supressed by:
|
152
|
+
Liblinear.quiet_mode
|
153
|
+
|
154
|
+
# You can undo by:
|
155
|
+
Liblinear.verbose_mode
|
156
|
+
```
|
157
|
+
|
141
158
|
## Thanks
|
142
159
|
- http://www.csie.ntu.edu.tw/~cjlin/liblinear/
|
143
160
|
- https://github.com/tomz/liblinear-ruby-swig
|
data/ext/liblinear.i
CHANGED
@@ -38,4 +38,21 @@ void feature_node_matrix_destroy(struct feature_node **matrix)
|
|
38
38
|
{
|
39
39
|
free(matrix);
|
40
40
|
}
|
41
|
+
|
42
|
+
static void print_string_stdout(const char *s)
|
43
|
+
{
|
44
|
+
fputs(s,stdout);
|
45
|
+
fflush(stdout);
|
46
|
+
}
|
47
|
+
|
48
|
+
void print_null(const char *s) {}
|
49
|
+
|
50
|
+
void enable_stdout() {
|
51
|
+
set_print_string_function(&print_string_stdout);
|
52
|
+
}
|
53
|
+
|
54
|
+
void disable_stdout() {
|
55
|
+
set_print_string_function(&print_null);
|
56
|
+
}
|
57
|
+
|
41
58
|
%}
|
data/ext/liblinear_wrap.cxx
CHANGED
@@ -2137,6 +2137,23 @@ void feature_node_matrix_destroy(struct feature_node **matrix)
|
|
2137
2137
|
free(matrix);
|
2138
2138
|
}
|
2139
2139
|
|
2140
|
+
static void print_string_stdout(const char *s)
|
2141
|
+
{
|
2142
|
+
fputs(s,stdout);
|
2143
|
+
fflush(stdout);
|
2144
|
+
}
|
2145
|
+
|
2146
|
+
void print_null(const char *s) {}
|
2147
|
+
|
2148
|
+
void enable_stdout() {
|
2149
|
+
set_print_string_function(&print_string_stdout);
|
2150
|
+
}
|
2151
|
+
|
2152
|
+
void disable_stdout() {
|
2153
|
+
set_print_string_function(&print_null);
|
2154
|
+
}
|
2155
|
+
|
2156
|
+
|
2140
2157
|
swig_class SwigClassFeature_node;
|
2141
2158
|
|
2142
2159
|
SWIGINTERN VALUE
|
@@ -4438,6 +4455,78 @@ fail:
|
|
4438
4455
|
}
|
4439
4456
|
|
4440
4457
|
|
4458
|
+
SWIGINTERN VALUE
|
4459
|
+
_wrap_print_string_stdout(int argc, VALUE *argv, VALUE self) {
|
4460
|
+
char *arg1 = (char *) 0 ;
|
4461
|
+
int res1 ;
|
4462
|
+
char *buf1 = 0 ;
|
4463
|
+
int alloc1 = 0 ;
|
4464
|
+
|
4465
|
+
if ((argc < 1) || (argc > 1)) {
|
4466
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
|
4467
|
+
}
|
4468
|
+
res1 = SWIG_AsCharPtrAndSize(argv[0], &buf1, NULL, &alloc1);
|
4469
|
+
if (!SWIG_IsOK(res1)) {
|
4470
|
+
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "char const *","print_string_stdout", 1, argv[0] ));
|
4471
|
+
}
|
4472
|
+
arg1 = reinterpret_cast< char * >(buf1);
|
4473
|
+
print_string_stdout((char const *)arg1);
|
4474
|
+
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
|
4475
|
+
return Qnil;
|
4476
|
+
fail:
|
4477
|
+
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
|
4478
|
+
return Qnil;
|
4479
|
+
}
|
4480
|
+
|
4481
|
+
|
4482
|
+
SWIGINTERN VALUE
|
4483
|
+
_wrap_print_null(int argc, VALUE *argv, VALUE self) {
|
4484
|
+
char *arg1 = (char *) 0 ;
|
4485
|
+
int res1 ;
|
4486
|
+
char *buf1 = 0 ;
|
4487
|
+
int alloc1 = 0 ;
|
4488
|
+
|
4489
|
+
if ((argc < 1) || (argc > 1)) {
|
4490
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc); SWIG_fail;
|
4491
|
+
}
|
4492
|
+
res1 = SWIG_AsCharPtrAndSize(argv[0], &buf1, NULL, &alloc1);
|
4493
|
+
if (!SWIG_IsOK(res1)) {
|
4494
|
+
SWIG_exception_fail(SWIG_ArgError(res1), Ruby_Format_TypeError( "", "char const *","print_null", 1, argv[0] ));
|
4495
|
+
}
|
4496
|
+
arg1 = reinterpret_cast< char * >(buf1);
|
4497
|
+
print_null((char const *)arg1);
|
4498
|
+
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
|
4499
|
+
return Qnil;
|
4500
|
+
fail:
|
4501
|
+
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
|
4502
|
+
return Qnil;
|
4503
|
+
}
|
4504
|
+
|
4505
|
+
|
4506
|
+
SWIGINTERN VALUE
|
4507
|
+
_wrap_enable_stdout(int argc, VALUE *argv, VALUE self) {
|
4508
|
+
if ((argc < 0) || (argc > 0)) {
|
4509
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
|
4510
|
+
}
|
4511
|
+
enable_stdout();
|
4512
|
+
return Qnil;
|
4513
|
+
fail:
|
4514
|
+
return Qnil;
|
4515
|
+
}
|
4516
|
+
|
4517
|
+
|
4518
|
+
SWIGINTERN VALUE
|
4519
|
+
_wrap_disable_stdout(int argc, VALUE *argv, VALUE self) {
|
4520
|
+
if ((argc < 0) || (argc > 0)) {
|
4521
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); SWIG_fail;
|
4522
|
+
}
|
4523
|
+
disable_stdout();
|
4524
|
+
return Qnil;
|
4525
|
+
fail:
|
4526
|
+
return Qnil;
|
4527
|
+
}
|
4528
|
+
|
4529
|
+
|
4441
4530
|
|
4442
4531
|
/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
|
4443
4532
|
|
@@ -4866,5 +4955,9 @@ SWIGEXPORT void Init_liblinearswig(void) {
|
|
4866
4955
|
rb_define_module_function(mLiblinearswig, "feature_node_matrix", VALUEFUNC(_wrap_feature_node_matrix), -1);
|
4867
4956
|
rb_define_module_function(mLiblinearswig, "feature_node_matrix_set", VALUEFUNC(_wrap_feature_node_matrix_set), -1);
|
4868
4957
|
rb_define_module_function(mLiblinearswig, "feature_node_matrix_destroy", VALUEFUNC(_wrap_feature_node_matrix_destroy), -1);
|
4958
|
+
rb_define_module_function(mLiblinearswig, "print_string_stdout", VALUEFUNC(_wrap_print_string_stdout), -1);
|
4959
|
+
rb_define_module_function(mLiblinearswig, "print_null", VALUEFUNC(_wrap_print_null), -1);
|
4960
|
+
rb_define_module_function(mLiblinearswig, "enable_stdout", VALUEFUNC(_wrap_enable_stdout), -1);
|
4961
|
+
rb_define_module_function(mLiblinearswig, "disable_stdout", VALUEFUNC(_wrap_disable_stdout), -1);
|
4869
4962
|
}
|
4870
4963
|
|
data/lib/liblinear.rb
CHANGED
data/lib/liblinear/version.rb
CHANGED
data/spec/liblinear_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liblinear-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kei Tsuchiya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,7 +117,6 @@ files:
|
|
117
117
|
- liblinear-2.1/windows/train.mexw64
|
118
118
|
- liblinear-ruby.gemspec
|
119
119
|
- spec/liblinear/array/double_spec.rb
|
120
|
-
- spec/liblinear/cross_validator_spec.rb
|
121
120
|
- spec/liblinear/example_spec.rb
|
122
121
|
- spec/liblinear/feature_node_matrix_spec.rb
|
123
122
|
- spec/liblinear/feature_node_spec.rb
|
@@ -145,13 +144,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
144
|
version: '0'
|
146
145
|
requirements: []
|
147
146
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.5.1
|
149
148
|
signing_key:
|
150
149
|
specification_version: 4
|
151
150
|
summary: Ruby wrapper of LIBLINEAR using SWIG
|
152
151
|
test_files:
|
153
152
|
- spec/liblinear/array/double_spec.rb
|
154
|
-
- spec/liblinear/cross_validator_spec.rb
|
155
153
|
- spec/liblinear/example_spec.rb
|
156
154
|
- spec/liblinear/feature_node_matrix_spec.rb
|
157
155
|
- spec/liblinear/feature_node_spec.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
$: << File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
|
2
|
-
require 'liblinear'
|
3
|
-
|
4
|
-
describe Liblinear::CrossValidator do
|
5
|
-
before do
|
6
|
-
@prob = Liblinear::Problem.new([1, 2], [[1],[2]])
|
7
|
-
@param_1 = Liblinear::Parameter.new
|
8
|
-
@param_2 = Liblinear::Parameter.new({ solver_type: Liblinear::L2R_L2LOSS_SVR })
|
9
|
-
|
10
|
-
@cv_classification = Liblinear::CrossValidator.new(@prob, @param_1, 2)
|
11
|
-
@cv_classification.execute
|
12
|
-
@cv_regression = Liblinear::CrossValidator.new(@prob, @param_2, 2)
|
13
|
-
@cv_regression.execute
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#accuracy' do
|
17
|
-
it 'returns accuracy' do
|
18
|
-
expect(@cv_classification.accuracy.class).to eq(Float)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#mean_squared_error' do
|
23
|
-
it 'returns mean_squared_error' do
|
24
|
-
expect(@cv_regression.mean_squared_error.class).to eq(Float)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'squared_correlation_coefficient' do
|
29
|
-
it 'returns squared_correlation_coefficient' do
|
30
|
-
expect(@cv_regression.squared_correlation_coefficient.class).to eq(Float)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|