xgboost.Booster
When using normal prediction with strict_shape set to True:
Output is a 2-dim array with first dimension as rows and second as groups. For
regression/survival/ranking/binary classification this is equivalent to a column vector
with shape[1] == 1. But for multi-class with multi:softprob the number of
columns equals to number of classes. If strict_shape is set to False then XGBoost might
output 1 or 2 dim array.
When using output_margin to avoid transformation and strict_shape is set to True:
Similar to the previous case, output is a 2-dim array, except for that multi:softmax
has equivalent output shape of multi:softprob due to dropped transformation. If
strict shape is set to False then output can have 1 or 2 dim depending on used model.
When using pred_contribs with strict_shape set to True:
Output is a 3-dim array, with (rows, groups, columns + 1) as shape. Whether
approx_contribs is used does not change the output shape. If the strict shape
parameter is not set, it can be a 2 or 3 dimension array depending on whether
multi-class model is being used.
When using pred_interactions with strict_shape set to True:
Output is a 4-dim array, with (rows, groups, columns + 1, columns + 1) as shape.
Like the predict contribution case, whether approx_contribs is used does not change
the output shape. If strict shape is set to False, it can have 3 or 4 dims depending on
the underlying model.
When using pred_leaf with strict_shape set to True:
Output is a 4-dim array with (n_samples, n_iterations, n_classes, n_trees_in_forest)
as shape. n_trees_in_forest is specified by the numb_parallel_tree during
training. When strict shape is set to False, output is a 2-dim array with last 3 dims
concatenated into 1. Also the last dimension is dropped if it equals to 1. When using
apply method in scikit learn interface, this is set to False by default.
For R package, when strict_shape is specified, an array is returned, with the same
value as Python except R array is column-major while Python numpy array is row-major, so
all the dimensions are reversed. For example, for a Python predict_leaf output
obtained by having strict_shape=True has 4 dimensions: (n_samples, n_iterations,
n_classes, n_trees_in_forest), while R with strict_shape=TRUE outputs
(n_trees_in_forest, n_classes, n_iterations, n_samples).
Other than these prediction types, there’s also a parameter called iteration_range,
which is similar to model slicing. But instead of actually splitting up the model into
multiple stacks, it simply returns the prediction formed by the trees within range.
Number of trees created in each iteration equals to treesi=num_class×num_parallel_tree. So if you are training a boosted random forest with size of 4, on
the 3-class classification dataset, and want to use the first 2 iterations of trees for
prediction, you need to provide iteration_range=(0, 2). Then the first 2×3×4 trees will be used in this prediction.