Demo for obtaining leaf index
.
join
(
CURRENT_DIR
,
"../data/agaricus.txt.train?format=libsvm"
)
)
dtest
=
xgb
.
DMatrix
(
(
CURRENT_DIR
,
"../data/agaricus.txt.test?format=libsvm"
)
)
param
=
{
"max_depth"
:
2
,
"eta"
:
1
,
"objective"
:
"binary:logistic"
}
watchlist
=
[(
dtest
,
"eval"
),
(
dtrain
,
"train"
)]
num_round
=
3
bst
=
xgb
.
train
(
param
,
dtrain
,
num_round
,
watchlist
)
print
(
"start testing predict the leaf indices"
)
leafindex
=
bst
.
predict
(
dtest
,
iteration_range
=
(
0
,
2
),
pred_leaf
=
True
,
strict_shape
=
True
)
print
(
leafindex
.
shape
)
print
(
leafindex
)
leafindex
=
bst
.
predict
(
dtest
,
pred_leaf
=
True
)
print
(
leafindex
.
shape
)