10
)
clf
.
set_params
(
base_score
=
0.5
)
In addition, here 0.5 represents the value after applying the inverse link function. See
the end of the document for a description.
Other than the base_score, users can also provide global bias via the data field
base_margin, which is a vector or a matrix depending on the task. With multi-output
and multi-class, the base_margin is a matrix with size (n_samples, n_targets) or
(n_samples, n_classes).
It specifies the bias for each sample and can be used for stacking an XGBoost model on top
of other models, see Demo for boosting from prediction for a worked
example. When base_margin is specified, it automatically overrides the base_score
parameter. If you are stacking XGBoost models, then the usage should be relatively
straightforward, with the previous model providing raw prediction and a new model using
the prediction as bias. For more customized inputs, users need to take extra care of the
link function. Let F be the model and g be the link function, since
base_score is overridden when sample-specific base_margin is available, we will
omit it here:
g(E[yi])=F(xi) When base margin b is provided, it’s added to the raw model output F:
g(E[yi])=F(xi)+bi and the output of the final model is:
g−1(F(xi)+bi) Using the gamma deviance objective reg:gamma as an example, which has a log link
function, hence:
ln(E[yi])=F(xi)+biE[yi]=exp(F(xi)+bi) As a result, if you are feeding outputs from models like GLM with a corresponding
objective function, make sure the outputs are not yet transformed by the inverse link
(activation).
In the case of base_score (intercept), it can be accessed through
save_config() after estimation. Unlike the base_margin, the
returned value represents a value after applying inverse link. With logistic regression
and the logit link function as an example, given the base_score as 0.5,
g(intercept)=logit(0.5)=0 is added to the raw model output:
E[yi]=g−1(F(xi)+g(intercept)) and 0.5 is the same as base_score=g−1(0)=0.5. This is more intuitive if
you remove the model and consider only the intercept, which is estimated before the model
is fitted:
E[y]=g−1(g(intercept))E[y]=intercept For some objectives like MAE, there are close solutions, while for others it’s estimated
with one step Newton method.
nrounds
=
10
)
m
<-
predict
(
model_1
,
agaricus.train
$
data
,
type
=
"raw"
)
model_2
<-
xgboost
(
x
=
agaricus.train
$
data
,
y
=
factor
(
agaricus.train
$
label
),
base_margin
=
m
,
nrounds
=
10
)
pred
<-
predict
(
model_2
,
agaricus.train
$
data
,
base_margin
=
m
)
xgb
.
DMatrix
(
X
,
y
))
booster
=
xgb
.
train
(
{
"base_score"
:
0.2
,
"objective"
:
"binary:logistic"
},
dtrain
=
Xy
,
num_boost_round
=
1
,
)
predt_1
=
booster
.
predict
(
Xy
)