| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/xgb.Booster.R |
| 3 |
\name{xgb.slice.Booster} |
| 4 |
\alias{xgb.slice.Booster} |
| 5 |
\alias{[.xgb.Booster} |
| 6 |
\title{Slice Booster by Rounds} |
| 7 |
\usage{ |
| 8 |
xgb.slice.Booster( |
| 9 |
model, |
| 10 |
start, |
| 11 |
end = xgb.get.num.boosted.rounds(model), |
| 12 |
step = 1L |
| 13 |
) |
| 14 |
|
| 15 |
\method{[}{xgb.Booster}(x, i) |
| 16 |
} |
| 17 |
\arguments{ |
| 18 |
\item{model, x}{A fitted \code{xgb.Booster} object, which is to be sliced by taking only a subset |
| 19 |
of its rounds / iterations.} |
| 20 |
|
| 21 |
\item{start}{Start of the slice (base-1 and inclusive, like R's \code{\link[=seq]{seq()}}).} |
| 22 |
|
| 23 |
\item{end}{End of the slice (base-1 and inclusive, like R's \code{\link[=seq]{seq()}}). |
| 24 |
Passing a value of zero here is equivalent to passing the full number of rounds in the |
| 25 |
booster object.} |
| 26 |
|
| 27 |
\item{step}{Step size of the slice. Passing '1' will take every round in the sequence defined by |
| 28 |
\verb{(start, end)}, while passing '2' will take every second value, and so on.} |
| 29 |
|
| 30 |
\item{i}{The indices - must be an increasing sequence as generated by e.g. \code{seq(...)}.} |
| 31 |
} |
| 32 |
\value{ |
| 33 |
A sliced booster object containing only the requested rounds. |
| 34 |
} |
| 35 |
\description{ |
| 36 |
Creates a new booster including only a selected range of rounds / iterations |
| 37 |
from an existing booster, as given by the sequence \code{seq(start, end, step)}. |
| 38 |
} |
| 39 |
\details{ |
| 40 |
Note that any R attributes that the booster might have, will not be copied into |
| 41 |
the resulting object. |
| 42 |
} |
| 43 |
\examples{ |
| 44 |
data(mtcars) |
| 45 |
|
| 46 |
y <- mtcars$mpg |
| 47 |
x <- as.matrix(mtcars[, -1]) |
| 48 |
|
| 49 |
dm <- xgb.DMatrix(x, label = y, nthread = 1) |
| 50 |
model <- xgb.train(data = dm, params = xgb.params(nthread = 1), nrounds = 5) |
| 51 |
model_slice <- xgb.slice.Booster(model, 1, 3) |
| 52 |
# Prediction for first three rounds |
| 53 |
predict(model, x, predleaf = TRUE)[, 1:3] |
| 54 |
|
| 55 |
# The new model has only those rounds, so |
| 56 |
# a full prediction from it is equivalent |
| 57 |
predict(model_slice, x, predleaf = TRUE) |
| 58 |
} |