@@ -53,6 +53,32 @@ impl Default for TreeMethod {
5353 fn default ( ) -> Self { TreeMethod :: Auto }
5454}
5555
56+ impl From < String > for TreeMethod
57+ {
58+ fn from ( s : String ) -> Self
59+ {
60+ use std:: borrow:: Borrow ;
61+ Self :: from ( s. borrow ( ) )
62+ }
63+ }
64+
65+ impl < ' a > From < & ' a str > for TreeMethod
66+ {
67+ fn from ( s : & ' a str ) -> Self
68+ {
69+ match s
70+ {
71+ "auto" => TreeMethod :: Auto ,
72+ "exact" => TreeMethod :: Exact ,
73+ "approx" => TreeMethod :: Approx ,
74+ "hist" => TreeMethod :: Hist ,
75+ "gpu_exact" => TreeMethod :: GpuExact ,
76+ "gpu_hist" => TreeMethod :: GpuHist ,
77+ _ => panic ! ( "no known tree_method for {}" , s)
78+ }
79+ }
80+ }
81+
5682/// Provides a modular way to construct and to modify the trees. This is an advanced parameter that is usually set
5783/// automatically, depending on some other parameters. However, it could be also set explicitly by a user.
5884#[ derive( Clone ) ]
@@ -191,7 +217,7 @@ pub struct TreeBoosterParameters {
191217 ///
192218 /// * range: [0,∞]
193219 /// * default: 0
194- gamma : u32 ,
220+ gamma : f32 ,
195221
196222 /// Maximum depth of a tree, increase this value will make the model more complex / likely to be overfitting.
197223 /// 0 indicates no limit, limit is required for depth-wise grow policy.
@@ -208,7 +234,7 @@ pub struct TreeBoosterParameters {
208234 ///
209235 /// * range: [0,∞]
210236 /// * default: 1
211- min_child_weight : u32 ,
237+ min_child_weight : f32 ,
212238
213239 /// Maximum delta step we allow each tree’s weight estimation to be.
214240 /// If the value is set to 0, it means there is no constraint. If it is set to a positive value,
@@ -218,7 +244,7 @@ pub struct TreeBoosterParameters {
218244 ///
219245 /// * range: [0,∞]
220246 /// * default: 0
221- max_delta_step : u32 ,
247+ max_delta_step : f32 ,
222248
223249 /// Subsample ratio of the training instance. Setting it to 0.5 means that XGBoost randomly collected half
224250 /// of the data instances to grow trees and this will prevent overfitting.
@@ -239,15 +265,21 @@ pub struct TreeBoosterParameters {
239265 /// * default: 1.0
240266 colsample_bylevel : f32 ,
241267
268+ /// Subsample ratio of columns for each node.
269+ ///
270+ /// * range: (0.0, 1.0]
271+ /// * default: 1.0
272+ colsample_bynode : f32 ,
273+
242274 /// L2 regularization term on weights, increase this value will make model more conservative.
243275 ///
244276 /// * default: 1
245- lambda : u32 ,
277+ lambda : f32 ,
246278
247279 /// L1 regularization term on weights, increase this value will make model more conservative.
248280 ///
249281 /// * default: 0
250- alpha : u32 ,
282+ alpha : f32 ,
251283
252284 /// The tree construction algorithm used in XGBoost.
253285 #[ builder( default = "TreeMethod::default()" ) ]
@@ -268,11 +300,6 @@ pub struct TreeBoosterParameters {
268300 /// default: 1.0
269301 scale_pos_weight : f32 ,
270302
271- /// Sequence of tree updaters to run, providing a modular way to construct and to modify the trees.
272- ///
273- /// * default: [TreeUpdater::GrowColMaker, TreeUpdater::Prune]
274- updater : Vec < TreeUpdater > ,
275-
276303 /// This is a parameter of the ‘refresh’ updater plugin. When this flag is true, tree leafs as well as tree nodes'
277304 /// stats are updated. When it is false, only node stats are updated.
278305 ///
@@ -300,6 +327,11 @@ pub struct TreeBoosterParameters {
300327 /// * default: 256
301328 max_bin : u32 ,
302329
330+ /// Number of trees to train in parallel for boosted random forest.
331+ ///
332+ /// * default: 1
333+ num_parallel_tree : u32 ,
334+
303335 /// The type of predictor algorithm to use. Provides the same results but allows the use of GPU or CPU.
304336 ///
305337 /// * default: [`Predictor::Cpu`](enum.Predictor.html#variant.Cpu)
@@ -310,24 +342,25 @@ impl Default for TreeBoosterParameters {
310342 fn default ( ) -> Self {
311343 TreeBoosterParameters {
312344 eta : 0.3 ,
313- gamma : 0 ,
345+ gamma : 0.0 ,
314346 max_depth : 6 ,
315- min_child_weight : 1 ,
316- max_delta_step : 0 ,
347+ min_child_weight : 1.0 ,
348+ max_delta_step : 0.0 ,
317349 subsample : 1.0 ,
318350 colsample_bytree : 1.0 ,
319351 colsample_bylevel : 1.0 ,
320- lambda : 1 ,
321- alpha : 0 ,
352+ colsample_bynode : 1.0 ,
353+ lambda : 1.0 ,
354+ alpha : 0.0 ,
322355 tree_method : TreeMethod :: default ( ) ,
323356 sketch_eps : 0.03 ,
324357 scale_pos_weight : 1.0 ,
325- updater : vec ! [ TreeUpdater :: GrowColMaker , TreeUpdater :: Prune ] ,
326358 refresh_leaf : true ,
327359 process_type : ProcessType :: default ( ) ,
328360 grow_policy : GrowPolicy :: default ( ) ,
329361 max_leaves : 0 ,
330362 max_bin : 256 ,
363+ num_parallel_tree : 1 ,
331364 predictor : Predictor :: default ( ) ,
332365 }
333366 }
@@ -347,17 +380,18 @@ impl TreeBoosterParameters {
347380 v. push ( ( "subsample" . to_owned ( ) , self . subsample . to_string ( ) ) ) ;
348381 v. push ( ( "colsample_bytree" . to_owned ( ) , self . colsample_bytree . to_string ( ) ) ) ;
349382 v. push ( ( "colsample_bylevel" . to_owned ( ) , self . colsample_bylevel . to_string ( ) ) ) ;
383+ v. push ( ( "colsample_bynode" . to_owned ( ) , self . colsample_bynode . to_string ( ) ) ) ;
350384 v. push ( ( "lambda" . to_owned ( ) , self . lambda . to_string ( ) ) ) ;
351385 v. push ( ( "alpha" . to_owned ( ) , self . alpha . to_string ( ) ) ) ;
352386 v. push ( ( "tree_method" . to_owned ( ) , self . tree_method . to_string ( ) ) ) ;
353387 v. push ( ( "sketch_eps" . to_owned ( ) , self . sketch_eps . to_string ( ) ) ) ;
354388 v. push ( ( "scale_pos_weight" . to_owned ( ) , self . scale_pos_weight . to_string ( ) ) ) ;
355- v. push ( ( "updater" . to_owned ( ) , self . updater . iter ( ) . map ( |u| u. to_string ( ) ) . collect :: < Vec < String > > ( ) . join ( "," ) ) ) ;
356389 v. push ( ( "refresh_leaf" . to_owned ( ) , ( self . refresh_leaf as u8 ) . to_string ( ) ) ) ;
357390 v. push ( ( "process_type" . to_owned ( ) , self . process_type . to_string ( ) ) ) ;
358391 v. push ( ( "grow_policy" . to_owned ( ) , self . grow_policy . to_string ( ) ) ) ;
359392 v. push ( ( "max_leaves" . to_owned ( ) , self . max_leaves . to_string ( ) ) ) ;
360393 v. push ( ( "max_bin" . to_owned ( ) , self . max_bin . to_string ( ) ) ) ;
394+ v. push ( ( "num_parallel_tree" . to_owned ( ) , self . num_parallel_tree . to_string ( ) ) ) ;
361395 v. push ( ( "predictor" . to_owned ( ) , self . predictor . to_string ( ) ) ) ;
362396
363397 v
@@ -370,6 +404,7 @@ impl TreeBoosterParametersBuilder {
370404 Interval :: new_open_closed ( 0.0 , 1.0 ) . validate ( & self . subsample , "subsample" ) ?;
371405 Interval :: new_open_closed ( 0.0 , 1.0 ) . validate ( & self . colsample_bytree , "colsample_bytree" ) ?;
372406 Interval :: new_open_closed ( 0.0 , 1.0 ) . validate ( & self . colsample_bylevel , "colsample_bylevel" ) ?;
407+ Interval :: new_open_closed ( 0.0 , 1.0 ) . validate ( & self . colsample_bynode , "colsample_bynode" ) ?;
373408 Interval :: new_open_open ( 0.0 , 1.0 ) . validate ( & self . sketch_eps , "sketch_eps" ) ?;
374409 Ok ( ( ) )
375410 }
0 commit comments