Get the quantile cuts (a.k.a. borders) from an xgb.DMatrix
that has been quantized for the histogram method (tree_method = "hist").
These cuts are used in order to assign observations to bins - i.e. these are ordered
boundaries which are used to determine assignment condition border_low < x < border_high.
As such, the first and last bin will be outside of the range of the data, so as to include
all of the observations there.
If a given column has 'n' bins, then there will be 'n+1' cuts / borders for that column, which will be output in sorted order from lowest to highest.
Different columns can have different numbers of bins according to their range.
Usage
xgb.get.DMatrix.qcut(dmat, output = c("list", "arrays"))Arguments
- dmat
An
xgb.DMatrixobject, as returned byxgb.DMatrix().- output
Output format for the quantile cuts. Possible options are:
"list"
will return the output as a list with one entry per column, where each column will have a numeric vector with the cuts. The list will be named ifdmat` has column names assigned to it."arrays"will return a list with entriesindptr(base-0 indexing) anddata. Here, the cuts for column 'i' are obtained by slicing 'data' from entriesindptr[i]+1toindptr[i+1].
Examples
data(mtcars)
y <- mtcars$mpg
x <- as.matrix(mtcars[, -1])
dm <- xgb.DMatrix(x, label = y, nthread = 1)
# DMatrix is not quantized right away, but will be once a hist model is generated
model <- xgb.train(
data = dm,
params = xgb.params(tree_method = "hist", max_bin = 8, nthread = 1),
nrounds = 3
)
# Now can get the quantile cuts
xgb.get.DMatrix.qcut(dm)
#> $cyl
#> [1] -0.00001 6.00000 8.00000 16.00001
#>
#> $disp
#> [1] -0.00001 95.10000 121.00000 160.00000 225.00000 275.79999 318.00000
#> [8] 360.00000 944.00000
#>
#> $hp
#> [1] -0.00001 66.00000 97.00000 110.00000 123.00000 175.00000 180.00000
#> [8] 230.00000 670.00000
#>
#> $drat
#> [1] -0.000010 3.070000 3.150000 3.230000 3.700000 3.900000 3.920000
#> [8] 4.110000 9.860009
#>
#> $wt
#> [1] -0.00001 2.14000 2.62000 3.15000 3.43500 3.44000 3.57000 3.84500
#> [9] 10.84801
#>
#> $qsec
#> [1] -0.00001 15.84000 16.90000 17.30000 17.82000 18.30000 18.90000 19.90000
#> [9] 45.80001
#>
#> $vs
#> [1] -0.00001 1.00000 2.00001
#>
#> $am
#> [1] -0.00001 1.00000 2.00001
#>
#> $gear
#> [1] -0.00001 4.00000 5.00000 10.00001
#>
#> $carb
#> [1] -0.00001 2.00000 3.00000 4.00000 6.00000 8.00000 16.00001
#>