从经过直方图方法 (tree_method = "hist"
) 量化处理的 xgb.DMatrix
对象中获取分位数切点(也称边界)。
这些切点用于将观测值分配到不同的分箱中 - 即,这些是有序的边界,用于确定分配条件 border_low < x < border_high
。因此,第一个和最后一个分箱将位于数据范围之外,以便包含所有观测值。
如果给定列有 'n' 个分箱,那么该列将有 'n+1' 个切点/边界,它们将按从低到高的排序顺序输出。
不同列根据其范围可以有不同数量的分箱。
用法
xgb.get.DMatrix.qcut(dmat, output = c("list", "arrays"))
参数
- dmat
一个
xgb.DMatrix
对象,由xgb.DMatrix()
返回。- output
分位数切点的输出格式。可能的选项有
"list"
将返回一个列表,其中每个列对应一个条目,每个条目包含该列的数值型切点向量。如果
dmat` 具有列名,则该列表也将具有列名。"arrays"
将返回一个包含indptr
(基 0 索引)和data
条目的列表。在此格式中,列 'i' 的切点通过对 'data' 从索引indptr[i]+1
到indptr[i+1]
进行切片获得。
示例
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)