xgb 0.9.0 → 0.11.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 +9 -0
- data/NOTICE.txt +2 -2
- data/README.md +2 -1
- data/lib/xgboost/booster.rb +6 -1
- data/lib/xgboost/callback_container.rb +0 -2
- data/lib/xgboost/classifier.rb +2 -2
- data/lib/xgboost/dmatrix.rb +34 -5
- data/lib/xgboost/ffi.rb +3 -1
- data/lib/xgboost/model.rb +5 -3
- data/lib/xgboost/regressor.rb +2 -2
- data/lib/xgboost/utils.rb +2 -4
- data/lib/xgboost/version.rb +1 -1
- data/lib/xgboost.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 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f5fd1670cc6fc20a352e85facd9abb1923195c14022e7f909fc588217e758973
|
|
4
|
+
data.tar.gz: 9bfe06f330635d6f4f5bbf71223be5a7d2f4891e394c12f697a10a18215bf694
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 90fe5e7cc050bf8d8a2079974501cb50ac886bcb1482160afca50c1cf598d836b59c324630cf00236ac8e089fe57fb618335dde4c9a22dd3d4a5bc7fd031f41c
|
|
7
|
+
data.tar.gz: 4d87ee477501874f53633c286bec193da8f731f7e14f3f9008ed2da68fd7e3f3f594c25bc47d8f940813546208ff50981731ab67204d140c0a9cdebba6727565
|
data/CHANGELOG.md
CHANGED
data/NOTICE.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
Copyright XGBoost contributors
|
|
2
|
-
Copyright 2019-
|
|
1
|
+
Copyright 2014-2025 XGBoost contributors
|
|
2
|
+
Copyright 2019-2025 Andrew Kane
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
|
@@ -126,7 +126,8 @@ model.feature_importances
|
|
|
126
126
|
Early stopping
|
|
127
127
|
|
|
128
128
|
```ruby
|
|
129
|
-
model.
|
|
129
|
+
model = XGBoost::Regressor.new(early_stopping_rounds: 5)
|
|
130
|
+
model.fit(x, y, eval_set: [[x_test, y_test]])
|
|
130
131
|
```
|
|
131
132
|
|
|
132
133
|
## Data
|
data/lib/xgboost/booster.rb
CHANGED
|
@@ -47,6 +47,11 @@ module XGBoost
|
|
|
47
47
|
json_string.read_pointer.read_string(length.read_uint64).force_encoding(Encoding::UTF_8)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
+
def reset
|
|
51
|
+
check_call FFI.XGBoosterReset(handle)
|
|
52
|
+
self
|
|
53
|
+
end
|
|
54
|
+
|
|
50
55
|
def attr(key)
|
|
51
56
|
ret = ::FFI::MemoryPointer.new(:pointer)
|
|
52
57
|
success = ::FFI::MemoryPointer.new(:int)
|
|
@@ -178,7 +183,7 @@ module XGBoost
|
|
|
178
183
|
|
|
179
184
|
names = feature_names || []
|
|
180
185
|
fnames = array_of_pointers(names.map { |fname| string_pointer(fname) })
|
|
181
|
-
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")))
|
|
182
187
|
|
|
183
188
|
check_call FFI.XGBoosterDumpModelExWithFeatures(handle, names.size, fnames, ftypes, with_stats ? 1 : 0, dump_format, out_len, out_result)
|
|
184
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module XGBoost
|
|
2
2
|
class Classifier < Model
|
|
3
|
-
def initialize(
|
|
3
|
+
def initialize(objective: "binary:logistic", **options)
|
|
4
4
|
super
|
|
5
5
|
end
|
|
6
6
|
|
|
@@ -18,7 +18,7 @@ module XGBoost
|
|
|
18
18
|
|
|
19
19
|
@booster = XGBoost.train(params, dtrain,
|
|
20
20
|
num_boost_round: @n_estimators,
|
|
21
|
-
early_stopping_rounds: early_stopping_rounds,
|
|
21
|
+
early_stopping_rounds: early_stopping_rounds || @early_stopping_rounds,
|
|
22
22
|
verbose_eval: verbose,
|
|
23
23
|
evals: evals
|
|
24
24
|
)
|
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,12 +33,14 @@ 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
|
|
39
40
|
attach_function :XGBoosterUpdateOneIter, %i[pointer int pointer], :int
|
|
40
41
|
attach_function :XGBoosterEvalOneIter, %i[pointer int pointer pointer uint64 pointer], :int
|
|
41
42
|
attach_function :XGBoosterFree, %i[pointer], :int
|
|
43
|
+
attach_function :XGBoosterReset, %i[pointer], :int
|
|
42
44
|
attach_function :XGBoosterBoostedRounds, %i[pointer pointer], :int
|
|
43
45
|
attach_function :XGBoosterSetParam, %i[pointer string string], :int
|
|
44
46
|
attach_function :XGBoosterGetNumFeature, %i[pointer pointer], :int
|
data/lib/xgboost/model.rb
CHANGED
|
@@ -2,10 +2,11 @@ module XGBoost
|
|
|
2
2
|
class Model
|
|
3
3
|
attr_reader :booster
|
|
4
4
|
|
|
5
|
-
def initialize(n_estimators: 100, importance_type: "gain", **options)
|
|
5
|
+
def initialize(n_estimators: 100, importance_type: "gain", early_stopping_rounds: nil, **options)
|
|
6
6
|
@params = options
|
|
7
7
|
@n_estimators = n_estimators
|
|
8
8
|
@importance_type = importance_type
|
|
9
|
+
@early_stopping_rounds = early_stopping_rounds
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def predict(data)
|
|
@@ -18,12 +19,13 @@ module XGBoost
|
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
def load_model(fname)
|
|
21
|
-
@booster = Booster.new(
|
|
22
|
+
@booster = Booster.new(model_file: fname)
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
def feature_importances
|
|
25
26
|
score = @booster.score(importance_type: @importance_type)
|
|
26
|
-
|
|
27
|
+
feature_names = @booster.feature_names || @booster.num_features.times.map { |i| "f#{i}" }
|
|
28
|
+
scores = feature_names.map { |k| score[k] || 0.0 }
|
|
27
29
|
total = scores.sum.to_f
|
|
28
30
|
scores.map { |s| s / total }
|
|
29
31
|
end
|
data/lib/xgboost/regressor.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module XGBoost
|
|
2
2
|
class Regressor < Model
|
|
3
|
-
def initialize(
|
|
3
|
+
def initialize(objective: "reg:squarederror", **options)
|
|
4
4
|
super
|
|
5
5
|
end
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ module XGBoost
|
|
|
10
10
|
|
|
11
11
|
@booster = XGBoost.train(@params, dtrain,
|
|
12
12
|
num_boost_round: @n_estimators,
|
|
13
|
-
early_stopping_rounds: early_stopping_rounds,
|
|
13
|
+
early_stopping_rounds: early_stopping_rounds || @early_stopping_rounds,
|
|
14
14
|
verbose_eval: verbose,
|
|
15
15
|
evals: evals
|
|
16
16
|
)
|
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
data/lib/xgboost.rb
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
metadata
CHANGED
|
@@ -1,14 +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.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kane
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: ffi
|
|
@@ -24,7 +23,6 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
27
|
-
description:
|
|
28
26
|
email: andrew@ankane.org
|
|
29
27
|
executables: []
|
|
30
28
|
extensions: []
|
|
@@ -73,7 +71,6 @@ homepage: https://github.com/ankane/xgboost-ruby
|
|
|
73
71
|
licenses:
|
|
74
72
|
- Apache-2.0
|
|
75
73
|
metadata: {}
|
|
76
|
-
post_install_message:
|
|
77
74
|
rdoc_options: []
|
|
78
75
|
require_paths:
|
|
79
76
|
- lib
|
|
@@ -81,15 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
81
78
|
requirements:
|
|
82
79
|
- - ">="
|
|
83
80
|
- !ruby/object:Gem::Version
|
|
84
|
-
version: '3.
|
|
81
|
+
version: '3.2'
|
|
85
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
83
|
requirements:
|
|
87
84
|
- - ">="
|
|
88
85
|
- !ruby/object:Gem::Version
|
|
89
86
|
version: '0'
|
|
90
87
|
requirements: []
|
|
91
|
-
rubygems_version: 3.
|
|
92
|
-
signing_key:
|
|
88
|
+
rubygems_version: 3.6.9
|
|
93
89
|
specification_version: 4
|
|
94
90
|
summary: High performance gradient boosting for Ruby
|
|
95
91
|
test_files: []
|