xgb 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41e23d36cc3404e32f22527f2ddfd112db2abd096fbdbf272bade29d032f0df6
4
- data.tar.gz: 5fb377835c2dce3ec1d4f6d734588f3d1e222e9fe35fa9bd127b0eb6198f7f7d
3
+ metadata.gz: ea879f0494a877766dd500203b7f4ec091607a0a0cae609bc3be50fb134b87eb
4
+ data.tar.gz: 1ff52f49405628aa837f4f6ff1558b4b1a624a311b4c359c0a0703499613d35d
5
5
  SHA512:
6
- metadata.gz: 6a6551eef35b0c560bccb2e23034cda55ee29bd6dd00840e7d8dc8a86b1df017433d270cbb7b1a812f65d92123c22459722266c7a813b4a9e5184d69ba5abe73
7
- data.tar.gz: 4f15acf5555c4a5db81e73113cc5dc0c47f438687d9ea85dae25d818395bd6ed27f162e7a0588c65e347ee51a805eb2d2a673113aad629f6b7903e31f4d5b2ff
6
+ metadata.gz: cd2dcbbc2300bbb5900ae1cdf8abe47fd2c0f0c8dc1b825f53c5988450405298e5b8693be243ed351f7f14715e9f5963eb7c00cd39c1b25983b449398804e6f5
7
+ data.tar.gz: 969c4472a3926f8cd6569269817086ed047e4e64132fd92ab1bb78ab5e8f294c3a4342cfc4e121b8a2866b8f534d1ffaa35b806d9968f198f87bb4de06a64348
data/CHANGELOG.md CHANGED
@@ -1,17 +1,24 @@
1
- ## 0.1.3
1
+ ## 0.2.0 (2020-01-26)
2
+
3
+ - Prefer `XGBoost` over `Xgb`
4
+ - Changed to Apache 2.0 license to match XGBoost
5
+ - Added shared libraries
6
+ - Added support for booster attributes
7
+
8
+ ## 0.1.3 (2019-10-27)
2
9
 
3
10
  - Added support for missing values
4
11
  - Fixed Daru training and prediction
5
12
  - Fixed error with JRuby
6
13
 
7
- ## 0.1.2
14
+ ## 0.1.2 (2019-08-19)
8
15
 
9
16
  - Friendlier message when XGBoost not found
10
17
  - Free memory when objects are destroyed
11
18
  - Added `Ranker`
12
19
  - Added early stopping to Scikit-Learn API
13
20
 
14
- ## 0.1.1
21
+ ## 0.1.1 (2019-08-16)
15
22
 
16
23
  - Added Scikit-Learn API
17
24
  - Added early stopping
@@ -20,6 +27,6 @@
20
27
  - Added many other methods
21
28
  - Fixed shape of multiclass predictions when loaded from file
22
29
 
23
- ## 0.1.0
30
+ ## 0.1.0 (2019-08-15)
24
31
 
25
32
  - First release
data/LICENSE.txt CHANGED
@@ -1,22 +1,202 @@
1
- Copyright (c) 2019 Andrew Kane
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/NOTICE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2019-2020 Andrew Kane
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md CHANGED
@@ -1,19 +1,11 @@
1
- # Xgb
1
+ # XGBoost
2
2
 
3
- [XGBoost](https://github.com/dmlc/xgboost) - the high performance machine learning library - for Ruby
3
+ [XGBoost](https://github.com/dmlc/xgboost) - high performance gradient boosting - for Ruby
4
4
 
5
- :fire: Uses the C API for blazing performance
6
-
7
- [![Build Status](https://travis-ci.org/ankane/xgb.svg?branch=master)](https://travis-ci.org/ankane/xgb)
5
+ [![Build Status](https://travis-ci.org/ankane/xgboost.svg?branch=master)](https://travis-ci.org/ankane/xgboost)
8
6
 
9
7
  ## Installation
10
8
 
11
- First, [install XGBoost](https://xgboost.readthedocs.io/en/latest/build.html). For Homebrew, use:
12
-
13
- ```sh
14
- brew install xgboost
15
- ```
16
-
17
9
  Add this line to your application’s Gemfile:
18
10
 
19
11
  ```ruby
@@ -22,7 +14,7 @@ gem 'xgb'
22
14
 
23
15
  ## Getting Started
24
16
 
25
- This library follows the [Python API](https://xgboost.readthedocs.io/en/latest/python/python_api.html), with the `get_` and `set_` prefixes removed from methods. Some methods and options are missing at the moment. PRs welcome!
17
+ This library follows the [Python API](https://xgboost.readthedocs.io/en/latest/python/python_api.html), with the `get_` and `set_` prefixes removed from methods to make it more Ruby-like.
26
18
 
27
19
  ## Learning API
28
20
 
@@ -37,14 +29,14 @@ Train a model
37
29
 
38
30
  ```ruby
39
31
  params = {objective: "reg:squarederror"}
40
- dtrain = Xgb::DMatrix.new(x, label: y)
41
- booster = Xgb.train(params, dtrain)
32
+ dtrain = XGBoost::DMatrix.new(x, label: y)
33
+ booster = XGBoost.train(params, dtrain)
42
34
  ```
43
35
 
44
36
  Predict
45
37
 
46
38
  ```ruby
47
- dtest = Xgb::DMatrix.new(x)
39
+ dtest = XGBoost::DMatrix.new(x)
48
40
  booster.predict(dtest)
49
41
  ```
50
42
 
@@ -57,7 +49,7 @@ booster.save_model("my.model")
57
49
  Load the model from a file
58
50
 
59
51
  ```ruby
60
- booster = Xgb::Booster.new(model_file: "my.model")
52
+ booster = XGBoost::Booster.new(model_file: "my.model")
61
53
  ```
62
54
 
63
55
  Get the importance of features
@@ -69,13 +61,20 @@ booster.score
69
61
  Early stopping
70
62
 
71
63
  ```ruby
72
- Xgb.train(params, dtrain, evals: [[dtrain, "train"], [dtest, "eval"]], early_stopping_rounds: 5)
64
+ XGBoost.train(params, dtrain, evals: [[dtrain, "train"], [dtest, "eval"]], early_stopping_rounds: 5)
73
65
  ```
74
66
 
75
67
  CV
76
68
 
77
69
  ```ruby
78
- Xgb.cv(params, dtrain, nfold: 3, verbose_eval: true)
70
+ XGBoost.cv(params, dtrain, nfold: 3, verbose_eval: true)
71
+ ```
72
+
73
+ Set metadata about a model [master]
74
+
75
+ ```ruby
76
+ booster["key"] = "value"
77
+ booster.attributes
79
78
  ```
80
79
 
81
80
  ## Scikit-Learn API
@@ -90,11 +89,11 @@ y = [1, 2, 3, 4]
90
89
  Train a model
91
90
 
92
91
  ```ruby
93
- model = Xgb::Regressor.new
92
+ model = XGBoost::Regressor.new
94
93
  model.fit(x, y)
95
94
  ```
96
95
 
97
- > For classification, use `Xgb::Classifier`
96
+ > For classification, use `XGBoost::Classifier`
98
97
 
99
98
  Predict
100
99
 
@@ -148,24 +147,6 @@ Or a Numo NArray
148
147
  Numo::DFloat.new(3, 2).seq
149
148
  ```
150
149
 
151
- ## XGBoost Installation
152
-
153
- There’s an experimental branch that includes XGBoost with the gem for easiest installation.
154
-
155
- ```ruby
156
- gem 'xgb', github: 'ankane/xgb', branch: 'vendor', submodules: true
157
- ```
158
-
159
- Please file an issue if it doesn’t work for you.
160
-
161
- You can also specify the path to XGBoost in an initializer:
162
-
163
- ```ruby
164
- Xgb.ffi_lib << "/path/to/xgboost/lib/libxgboost.so"
165
- ```
166
-
167
- > Use `libxgboost.dylib` for Mac and `xgboost.dll` for Windows
168
-
169
150
  ## Helpful Resources
170
151
 
171
152
  - [Parameters](https://xgboost.readthedocs.io/en/latest/parameter.html)
@@ -182,13 +163,22 @@ Thanks to the [xgboost](https://github.com/PairOnAir/xgboost-ruby) gem for servi
182
163
 
183
164
  ## History
184
165
 
185
- View the [changelog](https://github.com/ankane/xgb/blob/master/CHANGELOG.md)
166
+ View the [changelog](https://github.com/ankane/xgboost/blob/master/CHANGELOG.md)
186
167
 
187
168
  ## Contributing
188
169
 
189
170
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
190
171
 
191
- - [Report bugs](https://github.com/ankane/xgb/issues)
192
- - Fix bugs and [submit pull requests](https://github.com/ankane/xgb/pulls)
172
+ - [Report bugs](https://github.com/ankane/xgboost/issues)
173
+ - Fix bugs and [submit pull requests](https://github.com/ankane/xgboost/pulls)
193
174
  - Write, clarify, or fix documentation
194
175
  - Suggest or add new features
176
+
177
+ To get started with development and testing:
178
+
179
+ ```sh
180
+ git clone https://github.com/ankane/xgboost.git
181
+ cd xgboost
182
+ bundle install
183
+ bundle exec rake test
184
+ ```
data/lib/xgb.rb CHANGED
@@ -1,173 +1,4 @@
1
- # dependencies
2
- require "ffi"
1
+ require "xgboost"
3
2
 
4
- # modules
5
- require "xgb/utils"
6
- require "xgb/booster"
7
- require "xgb/dmatrix"
8
- require "xgb/version"
9
-
10
- # scikit-learn API
11
- require "xgb/model"
12
- require "xgb/classifier"
13
- require "xgb/ranker"
14
- require "xgb/regressor"
15
-
16
- module Xgb
17
- class Error < StandardError; end
18
-
19
- class << self
20
- attr_accessor :ffi_lib
21
- end
22
- self.ffi_lib = ["xgboost"]
23
-
24
- # friendlier error message
25
- autoload :FFI,"xgb/ffi"
26
-
27
- class << self
28
- def train(params, dtrain, num_boost_round: 10, evals: nil, early_stopping_rounds: nil, verbose_eval: true)
29
- booster = Booster.new(params: params)
30
- num_feature = dtrain.num_col
31
- booster.set_param("num_feature", num_feature)
32
- booster.feature_names = num_feature.times.map { |i| "f#{i}" }
33
- evals ||= []
34
-
35
- if early_stopping_rounds
36
- best_score = nil
37
- best_iter = nil
38
- best_message = nil
39
- end
40
-
41
- num_boost_round.times do |iteration|
42
- booster.update(dtrain, iteration)
43
-
44
- if evals.any?
45
- message = booster.eval_set(evals, iteration)
46
- res = message.split.map { |x| x.split(":") }[1..-1].map { |k, v| [k, v.to_f] }
47
-
48
- if early_stopping_rounds && iteration == 0
49
- metric = res[-1][0]
50
- puts "Will train until #{metric} hasn't improved in #{early_stopping_rounds.to_i} rounds." if verbose_eval
51
- end
52
-
53
- puts message if verbose_eval
54
- score = res[-1][1]
55
-
56
- # TODO handle larger better
57
- if best_score.nil? || score < best_score
58
- best_score = score
59
- best_iter = iteration
60
- best_message = message
61
- elsif iteration - best_iter >= early_stopping_rounds
62
- booster.best_iteration = best_iter
63
- puts "Stopping. Best iteration:\n#{best_message}" if verbose_eval
64
- break
65
- end
66
- end
67
- end
68
-
69
- booster
70
- end
71
-
72
- def cv(params, dtrain, num_boost_round: 10, nfold: 3, seed: 0, shuffle: true, verbose_eval: nil, show_stdv: true, early_stopping_rounds: nil)
73
- rand_idx = (0...dtrain.num_row).to_a
74
- rand_idx.shuffle!(random: Random.new(seed)) if shuffle
75
-
76
- kstep = (rand_idx.size / nfold.to_f).ceil
77
- test_id = rand_idx.each_slice(kstep).to_a[0...nfold]
78
- train_id = []
79
- nfold.times do |i|
80
- idx = test_id.dup
81
- idx.delete_at(i)
82
- train_id << idx.flatten
83
- end
84
-
85
- folds = train_id.zip(test_id)
86
- cvfolds = []
87
- folds.each do |(train_idx, test_idx)|
88
- fold_dtrain = dtrain.slice(train_idx)
89
- fold_dvalid = dtrain.slice(test_idx)
90
- booster = Booster.new(params: params)
91
- booster.set_param("num_feature", dtrain.num_col)
92
- cvfolds << [booster, fold_dtrain, fold_dvalid]
93
- end
94
-
95
- eval_hist = {}
96
-
97
- if early_stopping_rounds
98
- best_score = nil
99
- best_iter = nil
100
- end
101
-
102
- num_boost_round.times do |iteration|
103
- scores = {}
104
-
105
- cvfolds.each do |(booster, fold_dtrain, fold_dvalid)|
106
- booster.update(fold_dtrain, iteration)
107
- message = booster.eval_set([[fold_dtrain, "train"], [fold_dvalid, "test"]], iteration)
108
-
109
- res = message.split.map { |x| x.split(":") }[1..-1].map { |k, v| [k, v.to_f] }
110
- res.each do |k, v|
111
- (scores[k] ||= []) << v
112
- end
113
- end
114
-
115
- message_parts = ["[#{iteration}]"]
116
-
117
- last_mean = nil
118
- means = {}
119
- scores.each do |eval_name, vals|
120
- mean = mean(vals)
121
- stdev = stdev(vals)
122
-
123
- (eval_hist["#{eval_name}-mean"] ||= []) << mean
124
- (eval_hist["#{eval_name}-std"] ||= []) << stdev
125
-
126
- means[eval_name] = mean
127
- last_mean = mean
128
-
129
- if show_stdv
130
- message_parts << "%s:%g+%g" % [eval_name, mean, stdev]
131
- else
132
- message_parts << "%s:%g" % [eval_name, mean]
133
- end
134
- end
135
-
136
- if early_stopping_rounds
137
- score = last_mean
138
- # TODO handle larger better
139
- if best_score.nil? || score < best_score
140
- best_score = score
141
- best_iter = iteration
142
- elsif iteration - best_iter >= early_stopping_rounds
143
- eval_hist.each_key do |k|
144
- eval_hist[k] = eval_hist[k][0..best_iter]
145
- end
146
- break
147
- end
148
- end
149
-
150
- # put at end to keep output consistent with Python
151
- puts message_parts.join("\t") if verbose_eval
152
- end
153
-
154
- eval_hist
155
- end
156
-
157
- private
158
-
159
- def mean(arr)
160
- arr.sum / arr.size.to_f
161
- end
162
-
163
- # don't subtract one from arr.size
164
- def stdev(arr)
165
- m = mean(arr)
166
- sum = 0
167
- arr.each do |v|
168
- sum += (v - m) ** 2
169
- end
170
- Math.sqrt(sum / arr.size)
171
- end
172
- end
173
- end
3
+ # legacy
4
+ Xgb = XGBoost
data/lib/xgboost.rb ADDED
@@ -0,0 +1,175 @@
1
+ # dependencies
2
+ require "ffi"
3
+
4
+ # modules
5
+ require "xgboost/utils"
6
+ require "xgboost/booster"
7
+ require "xgboost/dmatrix"
8
+ require "xgboost/version"
9
+
10
+ # scikit-learn API
11
+ require "xgboost/model"
12
+ require "xgboost/classifier"
13
+ require "xgboost/ranker"
14
+ require "xgboost/regressor"
15
+
16
+ module XGBoost
17
+ class Error < StandardError; end
18
+
19
+ class << self
20
+ attr_accessor :ffi_lib
21
+ end
22
+ lib_name = FFI.map_library_name("xgboost")
23
+ vendor_lib = File.expand_path("../vendor/#{lib_name}", __dir__)
24
+ self.ffi_lib = [vendor_lib]
25
+
26
+ # friendlier error message
27
+ autoload :FFI, "xgboost/ffi"
28
+
29
+ class << self
30
+ def train(params, dtrain, num_boost_round: 10, evals: nil, early_stopping_rounds: nil, verbose_eval: true)
31
+ booster = Booster.new(params: params)
32
+ num_feature = dtrain.num_col
33
+ booster.set_param("num_feature", num_feature)
34
+ booster.feature_names = num_feature.times.map { |i| "f#{i}" }
35
+ evals ||= []
36
+
37
+ if early_stopping_rounds
38
+ best_score = nil
39
+ best_iter = nil
40
+ best_message = nil
41
+ end
42
+
43
+ num_boost_round.times do |iteration|
44
+ booster.update(dtrain, iteration)
45
+
46
+ if evals.any?
47
+ message = booster.eval_set(evals, iteration)
48
+ res = message.split.map { |x| x.split(":") }[1..-1].map { |k, v| [k, v.to_f] }
49
+
50
+ if early_stopping_rounds && iteration == 0
51
+ metric = res[-1][0]
52
+ puts "Will train until #{metric} hasn't improved in #{early_stopping_rounds.to_i} rounds." if verbose_eval
53
+ end
54
+
55
+ puts message if verbose_eval
56
+ score = res[-1][1]
57
+
58
+ # TODO handle larger better
59
+ if best_score.nil? || score < best_score
60
+ best_score = score
61
+ best_iter = iteration
62
+ best_message = message
63
+ elsif iteration - best_iter >= early_stopping_rounds
64
+ booster.best_iteration = best_iter
65
+ puts "Stopping. Best iteration:\n#{best_message}" if verbose_eval
66
+ break
67
+ end
68
+ end
69
+ end
70
+
71
+ booster
72
+ end
73
+
74
+ def cv(params, dtrain, num_boost_round: 10, nfold: 3, seed: 0, shuffle: true, verbose_eval: nil, show_stdv: true, early_stopping_rounds: nil)
75
+ rand_idx = (0...dtrain.num_row).to_a
76
+ rand_idx.shuffle!(random: Random.new(seed)) if shuffle
77
+
78
+ kstep = (rand_idx.size / nfold.to_f).ceil
79
+ test_id = rand_idx.each_slice(kstep).to_a[0...nfold]
80
+ train_id = []
81
+ nfold.times do |i|
82
+ idx = test_id.dup
83
+ idx.delete_at(i)
84
+ train_id << idx.flatten
85
+ end
86
+
87
+ folds = train_id.zip(test_id)
88
+ cvfolds = []
89
+ folds.each do |(train_idx, test_idx)|
90
+ fold_dtrain = dtrain.slice(train_idx)
91
+ fold_dvalid = dtrain.slice(test_idx)
92
+ booster = Booster.new(params: params)
93
+ booster.set_param("num_feature", dtrain.num_col)
94
+ cvfolds << [booster, fold_dtrain, fold_dvalid]
95
+ end
96
+
97
+ eval_hist = {}
98
+
99
+ if early_stopping_rounds
100
+ best_score = nil
101
+ best_iter = nil
102
+ end
103
+
104
+ num_boost_round.times do |iteration|
105
+ scores = {}
106
+
107
+ cvfolds.each do |(booster, fold_dtrain, fold_dvalid)|
108
+ booster.update(fold_dtrain, iteration)
109
+ message = booster.eval_set([[fold_dtrain, "train"], [fold_dvalid, "test"]], iteration)
110
+
111
+ res = message.split.map { |x| x.split(":") }[1..-1].map { |k, v| [k, v.to_f] }
112
+ res.each do |k, v|
113
+ (scores[k] ||= []) << v
114
+ end
115
+ end
116
+
117
+ message_parts = ["[#{iteration}]"]
118
+
119
+ last_mean = nil
120
+ means = {}
121
+ scores.each do |eval_name, vals|
122
+ mean = mean(vals)
123
+ stdev = stdev(vals)
124
+
125
+ (eval_hist["#{eval_name}-mean"] ||= []) << mean
126
+ (eval_hist["#{eval_name}-std"] ||= []) << stdev
127
+
128
+ means[eval_name] = mean
129
+ last_mean = mean
130
+
131
+ if show_stdv
132
+ message_parts << "%s:%g+%g" % [eval_name, mean, stdev]
133
+ else
134
+ message_parts << "%s:%g" % [eval_name, mean]
135
+ end
136
+ end
137
+
138
+ if early_stopping_rounds
139
+ score = last_mean
140
+ # TODO handle larger better
141
+ if best_score.nil? || score < best_score
142
+ best_score = score
143
+ best_iter = iteration
144
+ elsif iteration - best_iter >= early_stopping_rounds
145
+ eval_hist.each_key do |k|
146
+ eval_hist[k] = eval_hist[k][0..best_iter]
147
+ end
148
+ break
149
+ end
150
+ end
151
+
152
+ # put at end to keep output consistent with Python
153
+ puts message_parts.join("\t") if verbose_eval
154
+ end
155
+
156
+ eval_hist
157
+ end
158
+
159
+ private
160
+
161
+ def mean(arr)
162
+ arr.sum / arr.size.to_f
163
+ end
164
+
165
+ # don't subtract one from arr.size
166
+ def stdev(arr)
167
+ m = mean(arr)
168
+ sum = 0
169
+ arr.each do |v|
170
+ sum += (v - m) ** 2
171
+ end
172
+ Math.sqrt(sum / arr.size)
173
+ end
174
+ end
175
+ end
@@ -1,4 +1,4 @@
1
- module Xgb
1
+ module XGBoost
2
2
  class Booster
3
3
  attr_accessor :best_iteration, :feature_names
4
4
 
@@ -154,6 +154,34 @@ module Xgb
154
154
  end
155
155
  end
156
156
 
157
+ def [](key_name)
158
+ key = ::FFI::MemoryPointer.from_string(key_name)
159
+ success = ::FFI::MemoryPointer.new(:int)
160
+ out_result = ::FFI::MemoryPointer.new(:pointer)
161
+
162
+ check_result FFI.XGBoosterGetAttr(handle_pointer, key, out_result, success)
163
+
164
+ success.read_int == 1 ? out_result.read_pointer.read_string : nil
165
+ end
166
+
167
+ def []=(key_name, raw_value)
168
+ key = ::FFI::MemoryPointer.from_string(key_name)
169
+ value = raw_value.nil? ? nil : ::FFI::MemoryPointer.from_string(raw_value)
170
+
171
+ check_result FFI.XGBoosterSetAttr(handle_pointer, key, value)
172
+ end
173
+
174
+ def attributes
175
+ out_len = ::FFI::MemoryPointer.new(:uint64)
176
+ out_result = ::FFI::MemoryPointer.new(:pointer)
177
+ check_result FFI.XGBoosterGetAttrNames(handle_pointer, out_len, out_result)
178
+
179
+ len = read_uint64(out_len)
180
+ key_names = len.zero? ? [] : out_result.read_pointer.get_array_of_string(0, len)
181
+
182
+ key_names.map { |key_name| [key_name, self[key_name]] }.to_h
183
+ end
184
+
157
185
  private
158
186
 
159
187
  def handle_pointer
@@ -1,4 +1,4 @@
1
- module Xgb
1
+ module XGBoost
2
2
  class Classifier < Model
3
3
  def initialize(max_depth: 3, learning_rate: 0.1, n_estimators: 100, objective: "binary:logistic", importance_type: "gain", **options)
4
4
  super
@@ -16,7 +16,7 @@ module Xgb
16
16
  dtrain = DMatrix.new(x, label: y)
17
17
  evals = Array(eval_set).map.with_index { |v, i| [DMatrix.new(v[0], label: v[1]), "validation_#{i}"] }
18
18
 
19
- @booster = Xgb.train(params, dtrain,
19
+ @booster = XGBoost.train(params, dtrain,
20
20
  num_boost_round: @n_estimators,
21
21
  early_stopping_rounds: early_stopping_rounds,
22
22
  verbose_eval: verbose,
@@ -1,4 +1,4 @@
1
- module Xgb
1
+ module XGBoost
2
2
  class DMatrix
3
3
  attr_reader :data
4
4
 
@@ -26,7 +26,7 @@ module Xgb
26
26
 
27
27
  handle_missing(flat_data, missing)
28
28
  c_data = ::FFI::MemoryPointer.new(:float, nrow * ncol)
29
- c_data.put_array_of_float(0, flat_data)
29
+ c_data.write_array_of_float(flat_data)
30
30
  check_result FFI.XGDMatrixCreateFromMat(c_data, nrow, ncol, missing, @handle)
31
31
 
32
32
  ObjectSpace.define_finalizer(self, self.class.finalize(handle_pointer))
@@ -59,7 +59,7 @@ module Xgb
59
59
 
60
60
  def group=(group)
61
61
  c_data = ::FFI::MemoryPointer.new(:int, group.size)
62
- c_data.put_array_of_int(0, group)
62
+ c_data.write_array_of_int(group)
63
63
  check_result FFI.XGDMatrixSetGroup(handle_pointer, c_data, group.size)
64
64
  end
65
65
 
@@ -78,7 +78,7 @@ module Xgb
78
78
  def slice(rindex)
79
79
  res = DMatrix.new(nil)
80
80
  idxset = ::FFI::MemoryPointer.new(:int, rindex.count)
81
- idxset.put_array_of_int(0, rindex)
81
+ idxset.write_array_of_int(rindex)
82
82
  check_result FFI.XGDMatrixSliceDMatrix(handle_pointer, idxset, rindex.size, res.handle)
83
83
  res
84
84
  end
@@ -100,7 +100,7 @@ module Xgb
100
100
  def set_float_info(field, data)
101
101
  data = data.to_a unless data.is_a?(Array)
102
102
  c_data = ::FFI::MemoryPointer.new(:float, data.size)
103
- c_data.put_array_of_float(0, data)
103
+ c_data.write_array_of_float(data)
104
104
  check_result FFI.XGDMatrixSetFloatInfo(handle_pointer, field.to_s, c_data, data.size)
105
105
  end
106
106
 
@@ -1,9 +1,9 @@
1
- module Xgb
1
+ module XGBoost
2
2
  module FFI
3
3
  extend ::FFI::Library
4
4
 
5
5
  begin
6
- ffi_lib Xgb.ffi_lib
6
+ ffi_lib XGBoost.ffi_lib
7
7
  rescue LoadError => e
8
8
  raise e if ENV["XGB_DEBUG"]
9
9
  raise LoadError, "Could not find XGBoost"
@@ -36,5 +36,8 @@ module Xgb
36
36
  attach_function :XGBoosterLoadModel, %i[pointer string], :int
37
37
  attach_function :XGBoosterSaveModel, %i[pointer string], :int
38
38
  attach_function :XGBoosterDumpModelEx, %i[pointer string int string pointer pointer], :int
39
+ attach_function :XGBoosterGetAttr, %i[pointer pointer pointer pointer], :int
40
+ attach_function :XGBoosterSetAttr, %i[pointer pointer pointer], :int
41
+ attach_function :XGBoosterGetAttrNames, %i[pointer pointer pointer], :int
39
42
  end
40
43
  end
@@ -1,4 +1,4 @@
1
- module Xgb
1
+ module XGBoost
2
2
  class Model
3
3
  attr_reader :booster
4
4
 
@@ -1,4 +1,4 @@
1
- module Xgb
1
+ module XGBoost
2
2
  class Ranker < Model
3
3
  def initialize(max_depth: 3, learning_rate: 0.1, n_estimators: 100, objective: "rank:pairwise", importance_type: "gain", **options)
4
4
  super
@@ -7,7 +7,7 @@ module Xgb
7
7
  def fit(x, y, group)
8
8
  dtrain = DMatrix.new(x, label: y)
9
9
  dtrain.group = group
10
- @booster = Xgb.train(@params, dtrain, num_boost_round: @n_estimators)
10
+ @booster = XGBoost.train(@params, dtrain, num_boost_round: @n_estimators)
11
11
  nil
12
12
  end
13
13
  end
@@ -1,4 +1,4 @@
1
- module Xgb
1
+ module XGBoost
2
2
  class Regressor < Model
3
3
  def initialize(max_depth: 3, learning_rate: 0.1, n_estimators: 100, objective: "reg:squarederror", importance_type: "gain", **options)
4
4
  super
@@ -8,7 +8,7 @@ module Xgb
8
8
  dtrain = DMatrix.new(x, label: y)
9
9
  evals = Array(eval_set).map.with_index { |v, i| [DMatrix.new(v[0], label: v[1]), "validation_#{i}"] }
10
10
 
11
- @booster = Xgb.train(@params, dtrain,
11
+ @booster = XGBoost.train(@params, dtrain,
12
12
  num_boost_round: @n_estimators,
13
13
  early_stopping_rounds: early_stopping_rounds,
14
14
  verbose_eval: verbose,
@@ -1,4 +1,4 @@
1
- module Xgb
1
+ module XGBoost
2
2
  module Utils
3
3
  private
4
4
 
@@ -6,7 +6,7 @@ module Xgb
6
6
  if err != 0
7
7
  # make friendly
8
8
  message = FFI.XGBGetLastError.split("\n").first.split(/:\d+: /, 2).last
9
- raise Xgb::Error, message
9
+ raise XGBoost::Error, message
10
10
  end
11
11
  end
12
12
 
@@ -0,0 +1,3 @@
1
+ module XGBoost
2
+ VERSION = "0.2.0"
3
+ end
data/vendor/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) 2019 by Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
Binary file
Binary file
Binary file
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.1.3
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: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2020-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: numo-narray
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description:
84
98
  email: andrew@chartkick.com
85
99
  executables: []
@@ -88,20 +102,26 @@ extra_rdoc_files: []
88
102
  files:
89
103
  - CHANGELOG.md
90
104
  - LICENSE.txt
105
+ - NOTICE.txt
91
106
  - README.md
92
107
  - lib/xgb.rb
93
- - lib/xgb/booster.rb
94
- - lib/xgb/classifier.rb
95
- - lib/xgb/dmatrix.rb
96
- - lib/xgb/ffi.rb
97
- - lib/xgb/model.rb
98
- - lib/xgb/ranker.rb
99
- - lib/xgb/regressor.rb
100
- - lib/xgb/utils.rb
101
- - lib/xgb/version.rb
102
- homepage: https://github.com/ankane/xgb
108
+ - lib/xgboost.rb
109
+ - lib/xgboost/booster.rb
110
+ - lib/xgboost/classifier.rb
111
+ - lib/xgboost/dmatrix.rb
112
+ - lib/xgboost/ffi.rb
113
+ - lib/xgboost/model.rb
114
+ - lib/xgboost/ranker.rb
115
+ - lib/xgboost/regressor.rb
116
+ - lib/xgboost/utils.rb
117
+ - lib/xgboost/version.rb
118
+ - vendor/LICENSE
119
+ - vendor/libxgboost.dylib
120
+ - vendor/libxgboost.so
121
+ - vendor/xgboost.dll
122
+ homepage: https://github.com/ankane/xgboost
103
123
  licenses:
104
- - MIT
124
+ - Apache-2.0
105
125
  metadata: {}
106
126
  post_install_message:
107
127
  rdoc_options: []
@@ -118,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
138
  - !ruby/object:Gem::Version
119
139
  version: '0'
120
140
  requirements: []
121
- rubygems_version: 3.0.3
141
+ rubygems_version: 3.1.2
122
142
  signing_key:
123
143
  specification_version: 4
124
- summary: XGBoost - the high performance machine learning library - for Ruby
144
+ summary: High performance gradient boosting for Ruby
125
145
  test_files: []
data/lib/xgb/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Xgb
2
- VERSION = "0.1.3"
3
- end