xgb 0.3.0 → 0.3.1
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 +5 -0
- data/lib/xgboost.rb +2 -1
- data/lib/xgboost/booster.rb +21 -10
- data/lib/xgboost/dmatrix.rb +15 -1
- data/lib/xgboost/ffi.rb +1 -1
- data/lib/xgboost/version.rb +1 -1
- 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: 295787749986ba153354f61845509079f470a5d11015c20cb89a5c58f04b133a
|
4
|
+
data.tar.gz: e111099514e9a9a48d51a5033214a3e897eeff209302e47e1f30d79c818833c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 803003072dafa5d2de97da7721042b94315b125f62f4f524f818923c5e5f8d3277624b146cedd7b88d9ca0769bec074e99717fb27ce56f5d2bf079ba627d52f7
|
7
|
+
data.tar.gz: b9b14da27b6f8c03415d770c31dd16fdd112922daa2af3022df8554301eb5e43d0e873f21c65da13799e7a62d832cadbabff50188783aad5b5e7a577a9334005
|
data/CHANGELOG.md
CHANGED
data/lib/xgboost.rb
CHANGED
@@ -31,7 +31,8 @@ module XGBoost
|
|
31
31
|
booster = Booster.new(params: params)
|
32
32
|
num_feature = dtrain.num_col
|
33
33
|
booster.set_param("num_feature", num_feature)
|
34
|
-
booster.feature_names =
|
34
|
+
booster.feature_names = dtrain.feature_names
|
35
|
+
booster.feature_types = dtrain.feature_types
|
35
36
|
evals ||= []
|
36
37
|
|
37
38
|
if early_stopping_rounds
|
data/lib/xgboost/booster.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module XGBoost
|
2
2
|
class Booster
|
3
|
-
attr_accessor :best_iteration, :feature_names
|
3
|
+
attr_accessor :best_iteration, :feature_names, :feature_types
|
4
4
|
|
5
5
|
def initialize(params: nil, model_file: nil)
|
6
6
|
@handle = ::FFI::MemoryPointer.new(:pointer)
|
@@ -25,11 +25,8 @@ module XGBoost
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def eval_set(evals, iteration)
|
28
|
-
dmats =
|
29
|
-
|
30
|
-
|
31
|
-
evnames = ::FFI::MemoryPointer.new(:pointer, evals.size)
|
32
|
-
evnames.write_array_of_pointer(evals.map { |v| ::FFI::MemoryPointer.from_string(v[1]) })
|
28
|
+
dmats = array_of_pointers(evals.map { |v| v[0].handle_pointer })
|
29
|
+
evnames = array_of_pointers(evals.map { |v| string_pointer(v[1]) })
|
33
30
|
|
34
31
|
out_result = ::FFI::MemoryPointer.new(:pointer)
|
35
32
|
|
@@ -67,7 +64,13 @@ module XGBoost
|
|
67
64
|
def dump(fmap: "", with_stats: false, dump_format: "text")
|
68
65
|
out_len = ::FFI::MemoryPointer.new(:uint64)
|
69
66
|
out_result = ::FFI::MemoryPointer.new(:pointer)
|
70
|
-
|
67
|
+
|
68
|
+
names = feature_names || []
|
69
|
+
fnames = array_of_pointers(names.map { |fname| string_pointer(fname) })
|
70
|
+
ftypes = array_of_pointers(feature_types || Array.new(names.size, string_pointer("float")))
|
71
|
+
|
72
|
+
check_result FFI.XGBoosterDumpModelExWithFeatures(handle_pointer, names.size, fnames, ftypes, with_stats ? 1 : 0, dump_format, out_len, out_result)
|
73
|
+
|
71
74
|
out_result.read_pointer.get_array_of_string(0, read_uint64(out_len))
|
72
75
|
end
|
73
76
|
|
@@ -155,7 +158,7 @@ module XGBoost
|
|
155
158
|
end
|
156
159
|
|
157
160
|
def [](key_name)
|
158
|
-
key =
|
161
|
+
key = string_pointer(key_name)
|
159
162
|
success = ::FFI::MemoryPointer.new(:int)
|
160
163
|
out_result = ::FFI::MemoryPointer.new(:pointer)
|
161
164
|
|
@@ -165,8 +168,8 @@ module XGBoost
|
|
165
168
|
end
|
166
169
|
|
167
170
|
def []=(key_name, raw_value)
|
168
|
-
key =
|
169
|
-
value = raw_value.nil? ? nil :
|
171
|
+
key = string_pointer(key_name)
|
172
|
+
value = raw_value.nil? ? nil : string_pointer(raw_value)
|
170
173
|
|
171
174
|
check_result FFI.XGBoosterSetAttr(handle_pointer, key, value)
|
172
175
|
end
|
@@ -188,6 +191,14 @@ module XGBoost
|
|
188
191
|
@handle.read_pointer
|
189
192
|
end
|
190
193
|
|
194
|
+
def array_of_pointers(values)
|
195
|
+
::FFI::MemoryPointer.new(:pointer, values.size).write_array_of_pointer(values)
|
196
|
+
end
|
197
|
+
|
198
|
+
def string_pointer(value)
|
199
|
+
::FFI::MemoryPointer.from_string(value.to_s)
|
200
|
+
end
|
201
|
+
|
191
202
|
include Utils
|
192
203
|
end
|
193
204
|
end
|
data/lib/xgboost/dmatrix.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module XGBoost
|
2
2
|
class DMatrix
|
3
|
-
attr_reader :data
|
3
|
+
attr_reader :data, :feature_names, :feature_types
|
4
4
|
|
5
5
|
def initialize(data, label: nil, weight: nil, missing: Float::NAN)
|
6
6
|
@data = data
|
@@ -15,6 +15,18 @@ module XGBoost
|
|
15
15
|
elsif daru?(data)
|
16
16
|
nrow, ncol = data.shape
|
17
17
|
flat_data = data.map_rows(&:to_a).flatten
|
18
|
+
@feature_names = data.each_vector.map(&:name)
|
19
|
+
@feature_types =
|
20
|
+
data.each_vector.map(&:db_type).map do |v|
|
21
|
+
case v
|
22
|
+
when "INTEGER"
|
23
|
+
"int"
|
24
|
+
when "DOUBLE"
|
25
|
+
"float"
|
26
|
+
else
|
27
|
+
raise Error, "Unknown feature type: #{v}"
|
28
|
+
end
|
29
|
+
end
|
18
30
|
elsif narray?(data)
|
19
31
|
nrow, ncol = data.shape
|
20
32
|
flat_data = data.flatten.to_a
|
@@ -30,6 +42,8 @@ module XGBoost
|
|
30
42
|
check_result FFI.XGDMatrixCreateFromMat(c_data, nrow, ncol, missing, @handle)
|
31
43
|
|
32
44
|
ObjectSpace.define_finalizer(self, self.class.finalize(handle_pointer))
|
45
|
+
|
46
|
+
@feature_names ||= ncol.times.map { |i| "f#{i}" }
|
33
47
|
end
|
34
48
|
|
35
49
|
self.label = label if label
|
data/lib/xgboost/ffi.rb
CHANGED
@@ -31,7 +31,7 @@ module XGBoost
|
|
31
31
|
attach_function :XGBoosterPredict, %i[pointer pointer int int int pointer pointer], :int
|
32
32
|
attach_function :XGBoosterLoadModel, %i[pointer string], :int
|
33
33
|
attach_function :XGBoosterSaveModel, %i[pointer string], :int
|
34
|
-
attach_function :
|
34
|
+
attach_function :XGBoosterDumpModelExWithFeatures, %i[pointer int pointer pointer int string pointer pointer], :int
|
35
35
|
attach_function :XGBoosterGetAttr, %i[pointer pointer pointer pointer], :int
|
36
36
|
attach_function :XGBoosterSetAttr, %i[pointer pointer pointer], :int
|
37
37
|
attach_function :XGBoosterGetAttrNames, %i[pointer pointer pointer], :int
|
data/lib/xgboost/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xgb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
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-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|