lightgbm 0.1.9 → 0.2.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/LICENSE.txt +18 -18
- data/README.md +1 -1
- data/lib/lightgbm.rb +6 -9
- data/lib/lightgbm/booster.rb +15 -9
- data/lib/lightgbm/dataset.rb +6 -3
- data/lib/lightgbm/ffi.rb +6 -6
- data/lib/lightgbm/version.rb +1 -1
- data/vendor/lib_lightgbm.dll +0 -0
- data/vendor/lib_lightgbm.dylib +0 -0
- data/vendor/lib_lightgbm.so +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b3405aa832aaa365ce38d59bf5a36b318f8d02c1a236ea144eb9b102bf7f07e
|
|
4
|
+
data.tar.gz: 5be378b94486a668fffdc276a73ff62f24a24b644932bd776fd877f4b69b157a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 914379fe9271306117fc222534915f3c19de1c6b165ecc053f49b9089da0b85594c8430958f03f28a23d98fcf2879c4948c8d3e5fecee920c2984700928380ec
|
|
7
|
+
data.tar.gz: 4f93ae6b4a2c3123d452ecf41d7ada8473af397f12ddafb4e34b4e552aae4b6ef23ecb75b54ce3f7f64ba0985402c6172070de4afaca2ea614875f6d91c2de1a
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) Microsoft Corporation
|
|
4
|
+
Copyright (c) 2019-2020 Andrew Kane
|
|
4
5
|
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
the following conditions:
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
12
|
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
15
|
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
OF
|
|
22
|
-
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
data/README.md
CHANGED
data/lib/lightgbm.rb
CHANGED
|
@@ -61,16 +61,14 @@ module LightGBM
|
|
|
61
61
|
# print results
|
|
62
62
|
messages = []
|
|
63
63
|
|
|
64
|
+
eval_valid = booster.eval_valid
|
|
64
65
|
if valid_contain_train
|
|
65
|
-
|
|
66
|
-
booster.eval_train.reverse.each do |res|
|
|
67
|
-
messages << "%s's %s: %g" % [res[0], res[1], res[2]]
|
|
68
|
-
end
|
|
66
|
+
eval_valid = eval_valid + booster.eval_train
|
|
69
67
|
end
|
|
70
|
-
|
|
71
|
-
eval_valid = booster.eval_valid
|
|
72
68
|
# not sure why reversed in output
|
|
73
|
-
eval_valid.reverse
|
|
69
|
+
eval_valid.reverse!
|
|
70
|
+
|
|
71
|
+
eval_valid.each do |res|
|
|
74
72
|
messages << "%s's %s: %g" % [res[0], res[1], res[2]]
|
|
75
73
|
end
|
|
76
74
|
|
|
@@ -188,8 +186,7 @@ module LightGBM
|
|
|
188
186
|
# use best iteration from first metric if not stopped early
|
|
189
187
|
best_iteration ||= best_iter[best_iter.keys.first]
|
|
190
188
|
eval_hist.each_key do |k|
|
|
191
|
-
|
|
192
|
-
# eval_hist[k] = eval_hist[k].first(best_iteration + 1)
|
|
189
|
+
eval_hist[k] = eval_hist[k].first(best_iteration + 1)
|
|
193
190
|
end
|
|
194
191
|
end
|
|
195
192
|
|
data/lib/lightgbm/booster.rb
CHANGED
|
@@ -39,11 +39,12 @@ module LightGBM
|
|
|
39
39
|
buffer_len = 1 << 20
|
|
40
40
|
out_len = ::FFI::MemoryPointer.new(:int64)
|
|
41
41
|
out_str = ::FFI::MemoryPointer.new(:char, buffer_len)
|
|
42
|
-
|
|
42
|
+
feature_importance_type = 0 # TODO add option
|
|
43
|
+
check_result FFI.LGBM_BoosterDumpModel(handle_pointer, start_iteration, num_iteration, feature_importance_type, buffer_len, out_len, out_str)
|
|
43
44
|
actual_len = read_int64(out_len)
|
|
44
45
|
if actual_len > buffer_len
|
|
45
46
|
out_str = ::FFI::MemoryPointer.new(:char, actual_len)
|
|
46
|
-
check_result FFI.LGBM_BoosterDumpModel(handle_pointer, start_iteration, num_iteration, actual_len, out_len, out_str)
|
|
47
|
+
check_result FFI.LGBM_BoosterDumpModel(handle_pointer, start_iteration, num_iteration, feature_importance_type, actual_len, out_len, out_str)
|
|
47
48
|
end
|
|
48
49
|
out_str.read_string
|
|
49
50
|
end
|
|
@@ -86,11 +87,12 @@ module LightGBM
|
|
|
86
87
|
buffer_len = 1 << 20
|
|
87
88
|
out_len = ::FFI::MemoryPointer.new(:int64)
|
|
88
89
|
out_str = ::FFI::MemoryPointer.new(:char, buffer_len)
|
|
89
|
-
|
|
90
|
+
feature_importance_type = 0 # TODO add option
|
|
91
|
+
check_result FFI.LGBM_BoosterSaveModelToString(handle_pointer, start_iteration, num_iteration, feature_importance_type, buffer_len, out_len, out_str)
|
|
90
92
|
actual_len = read_int64(out_len)
|
|
91
93
|
if actual_len > buffer_len
|
|
92
94
|
out_str = ::FFI::MemoryPointer.new(:char, actual_len)
|
|
93
|
-
check_result FFI.LGBM_BoosterSaveModelToString(handle_pointer, start_iteration, num_iteration, actual_len, out_len, out_str)
|
|
95
|
+
check_result FFI.LGBM_BoosterSaveModelToString(handle_pointer, start_iteration, num_iteration, feature_importance_type, actual_len, out_len, out_str)
|
|
94
96
|
end
|
|
95
97
|
out_str.read_string
|
|
96
98
|
end
|
|
@@ -115,7 +117,7 @@ module LightGBM
|
|
|
115
117
|
end
|
|
116
118
|
|
|
117
119
|
# TODO support different prediction types
|
|
118
|
-
def predict(input, num_iteration: nil, **params)
|
|
120
|
+
def predict(input, start_iteration: nil, num_iteration: nil, **params)
|
|
119
121
|
input =
|
|
120
122
|
if daru?(input)
|
|
121
123
|
input.map_rows(&:to_a)
|
|
@@ -126,6 +128,7 @@ module LightGBM
|
|
|
126
128
|
singular = !input.first.is_a?(Array)
|
|
127
129
|
input = [input] if singular
|
|
128
130
|
|
|
131
|
+
start_iteration ||= 0
|
|
129
132
|
num_iteration ||= best_iteration
|
|
130
133
|
num_class ||= num_class()
|
|
131
134
|
|
|
@@ -136,7 +139,7 @@ module LightGBM
|
|
|
136
139
|
|
|
137
140
|
out_len = ::FFI::MemoryPointer.new(:int64)
|
|
138
141
|
out_result = ::FFI::MemoryPointer.new(:double, num_class * input.count)
|
|
139
|
-
check_result FFI.LGBM_BoosterPredictForMat(handle_pointer, data, 1, input.count, input.first.count, 1, 0, num_iteration, params_str(params), out_len, out_result)
|
|
142
|
+
check_result FFI.LGBM_BoosterPredictForMat(handle_pointer, data, 1, input.count, input.first.count, 1, 0, start_iteration, num_iteration, params_str(params), out_len, out_result)
|
|
140
143
|
out = out_result.read_array_of_double(read_int64(out_len))
|
|
141
144
|
out = out.each_slice(num_class).to_a if num_class > 1
|
|
142
145
|
|
|
@@ -145,7 +148,8 @@ module LightGBM
|
|
|
145
148
|
|
|
146
149
|
def save_model(filename, num_iteration: nil, start_iteration: 0)
|
|
147
150
|
num_iteration ||= best_iteration
|
|
148
|
-
|
|
151
|
+
feature_importance_type = 0 # TODO add
|
|
152
|
+
check_result FFI.LGBM_BoosterSaveModel(handle_pointer, start_iteration, num_iteration, feature_importance_type, filename)
|
|
149
153
|
self # consistent with Python API
|
|
150
154
|
end
|
|
151
155
|
|
|
@@ -175,10 +179,12 @@ module LightGBM
|
|
|
175
179
|
def eval_names
|
|
176
180
|
eval_counts ||= eval_counts()
|
|
177
181
|
out_len = ::FFI::MemoryPointer.new(:int)
|
|
182
|
+
out_buffer_len = ::FFI::MemoryPointer.new(:size_t)
|
|
178
183
|
out_strs = ::FFI::MemoryPointer.new(:pointer, eval_counts)
|
|
179
|
-
|
|
184
|
+
buffer_len = 255
|
|
185
|
+
str_ptrs = eval_counts.times.map { ::FFI::MemoryPointer.new(:char, buffer_len) }
|
|
180
186
|
out_strs.write_array_of_pointer(str_ptrs)
|
|
181
|
-
check_result FFI.LGBM_BoosterGetEvalNames(handle_pointer, out_len, out_strs)
|
|
187
|
+
check_result FFI.LGBM_BoosterGetEvalNames(handle_pointer, eval_counts, out_len, buffer_len, out_buffer_len, out_strs)
|
|
182
188
|
str_ptrs.map(&:read_string)
|
|
183
189
|
end
|
|
184
190
|
|
data/lib/lightgbm/dataset.rb
CHANGED
|
@@ -27,10 +27,13 @@ module LightGBM
|
|
|
27
27
|
def feature_names
|
|
28
28
|
# must preallocate space
|
|
29
29
|
num_feature_names = ::FFI::MemoryPointer.new(:int)
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
out_buffer_len = ::FFI::MemoryPointer.new(:size_t)
|
|
31
|
+
len = 1000
|
|
32
|
+
out_strs = ::FFI::MemoryPointer.new(:pointer, len)
|
|
33
|
+
buffer_len = 255
|
|
34
|
+
str_ptrs = len.times.map { ::FFI::MemoryPointer.new(:char, buffer_len) }
|
|
32
35
|
out_strs.write_array_of_pointer(str_ptrs)
|
|
33
|
-
check_result FFI.LGBM_DatasetGetFeatureNames(handle_pointer,
|
|
36
|
+
check_result FFI.LGBM_DatasetGetFeatureNames(handle_pointer, len, num_feature_names, buffer_len, out_buffer_len, out_strs)
|
|
34
37
|
str_ptrs[0, num_feature_names.read_int].map(&:read_string)
|
|
35
38
|
end
|
|
36
39
|
|
data/lib/lightgbm/ffi.rb
CHANGED
|
@@ -23,7 +23,7 @@ module LightGBM
|
|
|
23
23
|
attach_function :LGBM_DatasetCreateFromMat, %i[pointer int int32 int32 int string pointer pointer], :int
|
|
24
24
|
attach_function :LGBM_DatasetGetSubset, %i[pointer pointer int32 string pointer], :int
|
|
25
25
|
attach_function :LGBM_DatasetSetFeatureNames, %i[pointer pointer int], :int
|
|
26
|
-
attach_function :LGBM_DatasetGetFeatureNames, %i[pointer pointer pointer], :int
|
|
26
|
+
attach_function :LGBM_DatasetGetFeatureNames, %i[pointer int pointer size_t pointer pointer], :int
|
|
27
27
|
attach_function :LGBM_DatasetFree, %i[pointer], :int
|
|
28
28
|
attach_function :LGBM_DatasetSaveBinary, %i[pointer string], :int
|
|
29
29
|
attach_function :LGBM_DatasetDumpText, %i[pointer string], :int
|
|
@@ -44,13 +44,13 @@ module LightGBM
|
|
|
44
44
|
attach_function :LGBM_BoosterNumModelPerIteration, %i[pointer pointer], :int
|
|
45
45
|
attach_function :LGBM_BoosterNumberOfTotalModel, %i[pointer pointer], :int
|
|
46
46
|
attach_function :LGBM_BoosterGetEvalCounts, %i[pointer pointer], :int
|
|
47
|
-
attach_function :LGBM_BoosterGetEvalNames, %i[pointer pointer pointer], :int
|
|
47
|
+
attach_function :LGBM_BoosterGetEvalNames, %i[pointer int pointer size_t pointer pointer], :int
|
|
48
48
|
attach_function :LGBM_BoosterGetNumFeature, %i[pointer pointer], :int
|
|
49
49
|
attach_function :LGBM_BoosterGetEval, %i[pointer int pointer pointer], :int
|
|
50
|
-
attach_function :LGBM_BoosterPredictForMat, %i[pointer pointer int int32 int32 int int int string pointer pointer], :int
|
|
51
|
-
attach_function :LGBM_BoosterSaveModel, %i[pointer int int string], :int
|
|
52
|
-
attach_function :LGBM_BoosterSaveModelToString, %i[pointer int int int64 pointer pointer], :int
|
|
53
|
-
attach_function :LGBM_BoosterDumpModel, %i[pointer int int int64 pointer pointer], :int
|
|
50
|
+
attach_function :LGBM_BoosterPredictForMat, %i[pointer pointer int int32 int32 int int int int string pointer pointer], :int
|
|
51
|
+
attach_function :LGBM_BoosterSaveModel, %i[pointer int int int string], :int
|
|
52
|
+
attach_function :LGBM_BoosterSaveModelToString, %i[pointer int int int int64 pointer pointer], :int
|
|
53
|
+
attach_function :LGBM_BoosterDumpModel, %i[pointer int int int int64 pointer pointer], :int
|
|
54
54
|
attach_function :LGBM_BoosterFeatureImportance, %i[pointer int int pointer], :int
|
|
55
55
|
end
|
|
56
56
|
end
|
data/lib/lightgbm/version.rb
CHANGED
data/vendor/lib_lightgbm.dll
CHANGED
|
Binary file
|
data/vendor/lib_lightgbm.dylib
CHANGED
|
Binary file
|
data/vendor/lib_lightgbm.so
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lightgbm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kane
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-09-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ffi
|