xgb 0.10.0 → 0.11.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 +9 -0
- data/README.md +4 -4
- data/lib/xgboost/booster.rb +1 -1
- data/lib/xgboost/callback_container.rb +0 -2
- data/lib/xgboost/classifier.rb +1 -1
- data/lib/xgboost/dmatrix.rb +34 -5
- data/lib/xgboost/ffi.rb +2 -1
- data/lib/xgboost/model.rb +3 -2
- data/lib/xgboost/regressor.rb +1 -1
- data/lib/xgboost/utils.rb +2 -4
- data/lib/xgboost/version.rb +1 -1
- data/vendor/aarch64-linux/libxgboost.so +0 -0
- data/vendor/arm64-darwin/libxgboost.dylib +0 -0
- data/vendor/x64-mingw/xgboost.dll +0 -0
- data/vendor/x86_64-darwin/libxgboost.dylib +0 -0
- data/vendor/x86_64-linux/libxgboost.so +0 -0
- data/vendor/x86_64-linux-musl/libxgboost.so +0 -0
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a7428aac799cd2099ef2bc224c29436b63193b7e419950660f8f6580bd232805
|
|
4
|
+
data.tar.gz: f266b4e62bafccc3f9079a946defee85d775acc16f2b242b8402c9facc29a5ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57da6c5369b485d77c30651b5b33e241b5bc7d7fefb4a4271d5a819ced99e0cf9d3c7a10a0905da8fb18e317fb5021d12a6bb60af954562a22336d008ac78cf7
|
|
7
|
+
data.tar.gz: c4b17d123505772002444cd12372b2cae5e1205a8c24a2b08fdb815bd60733d3bce57af9592c636369ac7bb10a2fece82f58a070b9a6950447843f5322cae327
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -45,13 +45,13 @@ booster.predict(dtest)
|
|
|
45
45
|
Save the model to a file
|
|
46
46
|
|
|
47
47
|
```ruby
|
|
48
|
-
booster.save_model("
|
|
48
|
+
booster.save_model("model.json")
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
Load the model from a file
|
|
52
52
|
|
|
53
53
|
```ruby
|
|
54
|
-
booster = XGBoost::Booster.new(model_file: "
|
|
54
|
+
booster = XGBoost::Booster.new(model_file: "model.json")
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
Get the importance of features
|
|
@@ -108,13 +108,13 @@ model.predict(x)
|
|
|
108
108
|
Save the model to a file
|
|
109
109
|
|
|
110
110
|
```ruby
|
|
111
|
-
model.save_model("
|
|
111
|
+
model.save_model("model.json")
|
|
112
112
|
```
|
|
113
113
|
|
|
114
114
|
Load the model from a file
|
|
115
115
|
|
|
116
116
|
```ruby
|
|
117
|
-
model.load_model("
|
|
117
|
+
model.load_model("model.json")
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
Get the importance of features
|
data/lib/xgboost/booster.rb
CHANGED
|
@@ -183,7 +183,7 @@ module XGBoost
|
|
|
183
183
|
|
|
184
184
|
names = feature_names || []
|
|
185
185
|
fnames = array_of_pointers(names.map { |fname| string_pointer(fname) })
|
|
186
|
-
ftypes = array_of_pointers(feature_types || Array.new(names.size, string_pointer("float")))
|
|
186
|
+
ftypes = array_of_pointers(feature_types&.map { |v| string_pointer(v) } || Array.new(names.size, string_pointer("float")))
|
|
187
187
|
|
|
188
188
|
check_call FFI.XGBoosterDumpModelExWithFeatures(handle, names.size, fnames, ftypes, with_stats ? 1 : 0, dump_format, out_len, out_result)
|
|
189
189
|
|
|
@@ -110,7 +110,6 @@ module XGBoost
|
|
|
110
110
|
|
|
111
111
|
def aggcv(rlist)
|
|
112
112
|
cvmap = {}
|
|
113
|
-
idx = rlist[0].split[0]
|
|
114
113
|
rlist.each do |line|
|
|
115
114
|
arr = line.split
|
|
116
115
|
arr[1..].each_with_index do |it, metric_idx|
|
|
@@ -118,7 +117,6 @@ module XGBoost
|
|
|
118
117
|
(cvmap[[metric_idx, k]] ||= []) << v.to_f
|
|
119
118
|
end
|
|
120
119
|
end
|
|
121
|
-
msg = idx
|
|
122
120
|
results = []
|
|
123
121
|
cvmap.sort { |x| x[0][0] }.each do |(_, name), s|
|
|
124
122
|
mean = mean(s)
|
data/lib/xgboost/classifier.rb
CHANGED
data/lib/xgboost/dmatrix.rb
CHANGED
|
@@ -34,6 +34,17 @@ module XGBoost
|
|
|
34
34
|
elsif rover?(data)
|
|
35
35
|
nrow, ncol = data.shape
|
|
36
36
|
feature_names = data.keys
|
|
37
|
+
feature_types =
|
|
38
|
+
data.types.map do |_, v|
|
|
39
|
+
v = v.to_s
|
|
40
|
+
if v.start_with?("int") || v.start_with?("uint")
|
|
41
|
+
"int"
|
|
42
|
+
elsif v.start_with?("float")
|
|
43
|
+
"float"
|
|
44
|
+
else
|
|
45
|
+
raise Error, "Unknown feature type: #{v}"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
37
48
|
data = data.to_numo
|
|
38
49
|
else
|
|
39
50
|
nrow = data.count
|
|
@@ -56,7 +67,7 @@ module XGBoost
|
|
|
56
67
|
check_call FFI.XGDMatrixCreateFromMat(c_data, nrow, ncol, missing, out)
|
|
57
68
|
@handle = ::FFI::AutoPointer.new(out.read_pointer, FFI.method(:XGDMatrixFree))
|
|
58
69
|
|
|
59
|
-
self.feature_names = feature_names
|
|
70
|
+
self.feature_names = feature_names if feature_names
|
|
60
71
|
self.feature_types = feature_types if feature_types
|
|
61
72
|
|
|
62
73
|
self.label = label if label
|
|
@@ -76,9 +87,15 @@ module XGBoost
|
|
|
76
87
|
end
|
|
77
88
|
|
|
78
89
|
def group=(group)
|
|
79
|
-
c_data = ::FFI::MemoryPointer.new(:
|
|
80
|
-
c_data.
|
|
81
|
-
|
|
90
|
+
c_data = ::FFI::MemoryPointer.new(:uint32, group.size)
|
|
91
|
+
c_data.write_array_of_uint32(group)
|
|
92
|
+
interface = {
|
|
93
|
+
shape: [group.length],
|
|
94
|
+
typestr: "|u4",
|
|
95
|
+
data: [c_data.address, false],
|
|
96
|
+
version: 3
|
|
97
|
+
}
|
|
98
|
+
check_call FFI.XGDMatrixSetInfoFromInterface(handle, "group", JSON.generate(interface))
|
|
82
99
|
end
|
|
83
100
|
|
|
84
101
|
def label
|
|
@@ -89,6 +106,10 @@ module XGBoost
|
|
|
89
106
|
float_info("weight")
|
|
90
107
|
end
|
|
91
108
|
|
|
109
|
+
def group
|
|
110
|
+
uint_info("group_ptr")
|
|
111
|
+
end
|
|
112
|
+
|
|
92
113
|
def num_row
|
|
93
114
|
out = ::FFI::MemoryPointer.new(:uint64)
|
|
94
115
|
check_call FFI.XGDMatrixNumRow(handle, out)
|
|
@@ -234,7 +255,15 @@ module XGBoost
|
|
|
234
255
|
out_len = ::FFI::MemoryPointer.new(:uint64)
|
|
235
256
|
out_dptr = ::FFI::MemoryPointer.new(:float, num_row)
|
|
236
257
|
check_call FFI.XGDMatrixGetFloatInfo(handle, field, out_len, out_dptr)
|
|
237
|
-
out_dptr.read_pointer.read_array_of_float(num_row)
|
|
258
|
+
out_dptr.read_pointer.null? ? nil : out_dptr.read_pointer.read_array_of_float(num_row)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def uint_info(field)
|
|
262
|
+
num_row ||= num_row()
|
|
263
|
+
out_len = ::FFI::MemoryPointer.new(:uint64)
|
|
264
|
+
out_dptr = ::FFI::MemoryPointer.new(:uint32, num_row)
|
|
265
|
+
check_call FFI.XGDMatrixGetUIntInfo(handle, field, out_len, out_dptr)
|
|
266
|
+
out_dptr.read_pointer.null? ? nil : out_dptr.read_pointer.read_array_of_uint32(num_row)
|
|
238
267
|
end
|
|
239
268
|
|
|
240
269
|
def validate_feature_info(feature_info, n_features, is_column_split, name)
|
data/lib/xgboost/ffi.rb
CHANGED
|
@@ -21,7 +21,7 @@ module XGBoost
|
|
|
21
21
|
|
|
22
22
|
# dmatrix
|
|
23
23
|
attach_function :XGDMatrixCreateFromMat, %i[pointer uint64 uint64 float pointer], :int
|
|
24
|
-
attach_function :
|
|
24
|
+
attach_function :XGDMatrixSetInfoFromInterface, %i[pointer string string], :int
|
|
25
25
|
attach_function :XGDMatrixSetStrFeatureInfo, %i[pointer string pointer uint64], :int
|
|
26
26
|
attach_function :XGDMatrixGetStrFeatureInfo, %i[pointer string pointer pointer], :int
|
|
27
27
|
attach_function :XGDMatrixNumRow, %i[pointer pointer], :int
|
|
@@ -33,6 +33,7 @@ module XGBoost
|
|
|
33
33
|
attach_function :XGDMatrixSaveBinary, %i[pointer string int], :int
|
|
34
34
|
attach_function :XGDMatrixSetFloatInfo, %i[pointer string pointer uint64], :int
|
|
35
35
|
attach_function :XGDMatrixGetFloatInfo, %i[pointer string pointer pointer], :int
|
|
36
|
+
attach_function :XGDMatrixGetUIntInfo, %i[pointer string pointer pointer], :int
|
|
36
37
|
|
|
37
38
|
# booster
|
|
38
39
|
attach_function :XGBoosterCreate, %i[pointer int pointer], :int
|
data/lib/xgboost/model.rb
CHANGED
|
@@ -19,12 +19,13 @@ module XGBoost
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def load_model(fname)
|
|
22
|
-
@booster = Booster.new(
|
|
22
|
+
@booster = Booster.new(model_file: fname)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def feature_importances
|
|
26
26
|
score = @booster.score(importance_type: @importance_type)
|
|
27
|
-
|
|
27
|
+
feature_names = @booster.feature_names || @booster.num_features.times.map { |i| "f#{i}" }
|
|
28
|
+
scores = feature_names.map { |k| score[k] || 0.0 }
|
|
28
29
|
total = scores.sum.to_f
|
|
29
30
|
scores.map { |s| s / total }
|
|
30
31
|
end
|
data/lib/xgboost/regressor.rb
CHANGED
data/lib/xgboost/utils.rb
CHANGED
|
@@ -23,11 +23,9 @@ module XGBoost
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def from_cstr_to_rbstr(data, length)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
res << data.read_pointer[i * ::FFI::Pointer.size].read_pointer.read_string.force_encoding(Encoding::UTF_8)
|
|
26
|
+
data.read_pointer.read_array_of_pointer(length.read_uint64).map do |ptr|
|
|
27
|
+
ptr.read_string.force_encoding(Encoding::UTF_8)
|
|
29
28
|
end
|
|
30
|
-
res
|
|
31
29
|
end
|
|
32
30
|
end
|
|
33
31
|
end
|
data/lib/xgboost/version.rb
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: xgb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.11.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kane
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: ffi
|
|
@@ -78,14 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
78
78
|
requirements:
|
|
79
79
|
- - ">="
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: '3.
|
|
81
|
+
version: '3.2'
|
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
requirements:
|
|
84
84
|
- - ">="
|
|
85
85
|
- !ruby/object:Gem::Version
|
|
86
86
|
version: '0'
|
|
87
87
|
requirements: []
|
|
88
|
-
rubygems_version:
|
|
88
|
+
rubygems_version: 4.0.3
|
|
89
89
|
specification_version: 4
|
|
90
90
|
summary: High performance gradient boosting for Ruby
|
|
91
91
|
test_files: []
|