File tree 3 files changed +27
-5
lines changed
3 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ Contents
13
13
sklearn_estimator
14
14
python_api
15
15
callbacks
16
- model
17
16
examples/index
18
17
dask-examples/index
19
18
survival-examples/index
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ See `Awesome XGBoost <https://github.com/dmlc/xgboost/tree/master/demo>`_ for mo
11
11
12
12
model
13
13
saving_model
14
+ slicing_model
14
15
learning_to_rank
15
16
dart
16
17
monotonic
Original file line number Diff line number Diff line change 1
- #####
2
- Model
3
- #####
1
+ ##############
2
+ Slicing Models
3
+ ##############
4
4
5
5
Slice tree model
6
6
----------------
7
7
8
8
When ``booster `` is set to ``gbtree `` or ``dart ``, XGBoost builds a tree model, which is a
9
9
list of trees and can be sliced into multiple sub-models.
10
10
11
+ In Python:
12
+
11
13
.. code-block :: python
12
14
13
15
from sklearn.datasets import make_classification
@@ -32,6 +34,24 @@ list of trees and can be sliced into multiple sub-models.
32
34
trees = [_ for _ in booster]
33
35
assert len (trees) == num_boost_round
34
36
37
+ In R:
38
+
39
+ .. versionadded :: 3.0.0
40
+
41
+ .. code-block :: R
42
+
43
+ data(agaricus.train, package = "xgboost")
44
+ dm <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
45
+
46
+ model <- xgb.train(
47
+ params = xgb.params(objective = "binary:logistic", max_depth = 4),
48
+ data = dm,
49
+ nrounds = 20
50
+ )
51
+ sliced <- model[seq(3, 7)]
52
+ ##### xgb.Booster
53
+ # of features: 126
54
+ # of rounds: 5
35
55
36
56
The sliced model is a copy of selected trees, that means the model itself is immutable
37
57
during slicing. This feature is the basis of `save_best ` option in early stopping
@@ -40,4 +60,6 @@ how to combine prediction with sliced trees.
40
60
41
61
.. note ::
42
62
43
- The returned model slice doesn't contain attributes like :py:class: `~xgboost.Booster.best_iteration ` and :py:class: `~xgboost.Booster.best_score `.
63
+ The returned model slice doesn't contain attributes like
64
+ :py:class: `~xgboost.Booster.best_iteration ` and
65
+ :py:class: `~xgboost.Booster.best_score `.
You can’t perform that action at this time.
0 commit comments