Module: XGBoost
- Defined in:
- lib/xgboost.rb,
lib/xgboost/ffi.rb,
lib/xgboost/model.rb,
lib/xgboost/utils.rb,
lib/xgboost/ranker.rb,
lib/xgboost/booster.rb,
lib/xgboost/cv_pack.rb,
lib/xgboost/dmatrix.rb,
lib/xgboost/version.rb,
lib/xgboost/regressor.rb,
lib/xgboost/classifier.rb,
lib/xgboost/early_stopping.rb,
lib/xgboost/packed_booster.rb,
lib/xgboost/training_callback.rb,
lib/xgboost/callback_container.rb,
lib/xgboost/evaluation_monitor.rb
Defined Under Namespace
Modules: FFI, Utils Classes: Booster, CVPack, CallbackContainer, Classifier, DMatrix, EarlyStopping, Error, EvaluationMonitor, Model, PackedBooster, Ranker, Regressor, TrainingCallback
Constant Summary collapse
- VERSION =
"0.10.0"
Class Attribute Summary collapse
-
.ffi_lib ⇒ Object
Returns the value of attribute ffi_lib.
Class Method Summary collapse
- .cv(params, dtrain, num_boost_round: 10, nfold: 3, maximize: nil, early_stopping_rounds: nil, verbose_eval: nil, show_stdv: true, seed: 0, callbacks: nil, shuffle: true) ⇒ Object
- .lib_version ⇒ Object
- .train(params, dtrain, num_boost_round: 10, evals: nil, maximize: nil, early_stopping_rounds: nil, evals_result: nil, verbose_eval: true, callbacks: nil) ⇒ Object
Class Attribute Details
.ffi_lib ⇒ Object
Returns the value of attribute ffi_lib.
28 29 30 |
# File 'lib/xgboost.rb', line 28 def ffi_lib @ffi_lib end |
Class Method Details
.cv(params, dtrain, num_boost_round: 10, nfold: 3, maximize: nil, early_stopping_rounds: nil, verbose_eval: nil, show_stdv: true, seed: 0, callbacks: nil, shuffle: true) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/xgboost.rb', line 97 def cv( params, dtrain, num_boost_round: 10, nfold: 3, maximize: nil, early_stopping_rounds: nil, verbose_eval: nil, show_stdv: true, seed: 0, callbacks: nil, shuffle: true ) results = {} cvfolds = mknfold( dall: dtrain, param: params, nfold: nfold, seed: seed, shuffle: shuffle ) callbacks = callbacks.nil? ? [] : callbacks.dup if verbose_eval verbose_eval = verbose_eval == true ? 1 : verbose_eval callbacks << EvaluationMonitor.new(period: verbose_eval, show_stdv: show_stdv) end if early_stopping_rounds callbacks << EarlyStopping.new(rounds: early_stopping_rounds, maximize: maximize) end callbacks_container = CallbackContainer.new(callbacks, is_cv: true) booster = PackedBooster.new(cvfolds) callbacks_container.before_training(booster) num_boost_round.times do |i| break if callbacks_container.before_iteration(booster, i, dtrain, nil) booster.update(i) should_break = callbacks_container.after_iteration(booster, i, dtrain, nil) res = callbacks_container.aggregated_cv res.each do |key, mean, std| if !results.include?(key + "-mean") results[key + "-mean"] = [] end if !results.include?(key + "-std") results[key + "-std"] = [] end results[key + "-mean"] << mean results[key + "-std"] << std end if should_break results.keys.each do |k| results[k] = results[k][..booster.best_iteration] end break end end callbacks_container.after_training(booster) results end |
.lib_version ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/xgboost.rb', line 164 def lib_version major = ::FFI::MemoryPointer.new(:int) minor = ::FFI::MemoryPointer.new(:int) patch = ::FFI::MemoryPointer.new(:int) FFI.XGBoostVersion(major, minor, patch) "#{major.read_int}.#{minor.read_int}.#{patch.read_int}" end |
.train(params, dtrain, num_boost_round: 10, evals: nil, maximize: nil, early_stopping_rounds: nil, evals_result: nil, verbose_eval: true, callbacks: nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/xgboost.rb', line 55 def train( params, dtrain, num_boost_round: 10, evals: nil, maximize: nil, early_stopping_rounds: nil, evals_result: nil, verbose_eval: true, callbacks: nil ) callbacks = callbacks.nil? ? [] : callbacks.dup evals ||= [] bst = Booster.new(params: params, cache: [dtrain] + evals.map { |d| d[0] }) if verbose_eval verbose_eval = verbose_eval == true ? 1 : verbose_eval callbacks << EvaluationMonitor.new(period: verbose_eval) end if early_stopping_rounds callbacks << EarlyStopping.new(rounds: early_stopping_rounds, maximize: maximize) end cb_container = CallbackContainer.new(callbacks) bst = cb_container.before_training(bst) num_boost_round.times do |i| break if cb_container.before_iteration(bst, i, dtrain, evals) bst.update(dtrain, i) break if cb_container.after_iteration(bst, i, dtrain, evals) end bst = cb_container.after_training(bst) if !evals_result.nil? evals_result.merge!(cb_container.history) end bst.reset end |