xgb 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c717478c585e099431318c391c7c054b58c844f5ddb19dd5d23f921acbea5b26
4
- data.tar.gz: dd221a13627c57135ef2e6e87f267889a76692f1417014e5728b5c279b44a2d5
3
+ metadata.gz: f5fd1670cc6fc20a352e85facd9abb1923195c14022e7f909fc588217e758973
4
+ data.tar.gz: 9bfe06f330635d6f4f5bbf71223be5a7d2f4891e394c12f697a10a18215bf694
5
5
  SHA512:
6
- metadata.gz: 4430473a5999cde2447f0782be837f1fb06db44eb3e823621ae94db96b356b40e04a772fa211819ed5915324a10b54ccb0b595d7368aaa22d31f6be4eb13fd0d
7
- data.tar.gz: eccc8f38705f82f2aa963c672df5515aa345926af91f9f94beab5fd01406a8d5ad84807d3609dec321952d28d8b2da575b880220ae8375d4296a2c34bf6b0b97
6
+ metadata.gz: 90fe5e7cc050bf8d8a2079974501cb50ac886bcb1482160afca50c1cf598d836b59c324630cf00236ac8e089fe57fb618335dde4c9a22dd3d4a5bc7fd031f41c
7
+ data.tar.gz: 4d87ee477501874f53633c286bec193da8f731f7e14f3f9008ed2da68fd7e3f3f594c25bc47d8f940813546208ff50981731ab67204d140c0a9cdebba6727565
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.11.0 (2025-10-18)
2
+
3
+ - Updated XGBoost to 3.1.0
4
+ - Dropped support for Ruby < 3.2
5
+
1
6
  ## 0.10.0 (2025-03-15)
2
7
 
3
8
  - Updated XGBoost to 3.0.0
@@ -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)
@@ -1,6 +1,6 @@
1
1
  module XGBoost
2
2
  class Classifier < Model
3
- def initialize(n_estimators: 100, objective: "binary:logistic", importance_type: "gain", **options)
3
+ def initialize(objective: "binary:logistic", **options)
4
4
  super
5
5
  end
6
6
 
@@ -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 || ncol.times.map { |i| "f#{i}" }
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(:int, group.size)
80
- c_data.write_array_of_int(group)
81
- check_call FFI.XGDMatrixSetUIntInfo(handle, "group", c_data, group.size)
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 :XGDMatrixSetUIntInfo, %i[pointer string pointer uint64], :int
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(params: @params, model_file: fname)
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
- scores = @booster.feature_names.map { |k| score[k] || 0.0 }
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
@@ -1,6 +1,6 @@
1
1
  module XGBoost
2
2
  class Regressor < Model
3
- def initialize(n_estimators: 100, objective: "reg:squarederror", importance_type: "gain", **options)
3
+ def initialize(objective: "reg:squarederror", **options)
4
4
  super
5
5
  end
6
6
 
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
- res = []
27
- length.read_uint64.times do |i|
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
@@ -1,3 +1,3 @@
1
1
  module XGBoost
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
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.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-15 00:00:00.000000000 Z
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.1'
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: 3.6.2
88
+ rubygems_version: 3.6.9
89
89
  specification_version: 4
90
90
  summary: High performance gradient boosting for Ruby
91
91
  test_files: []