跳到内容

检查 xgb.DMatrix 对象是否已分配了给定字段,例如权重(weights)、标签(labels)等。

用法

xgb.DMatrix.hasinfo(object, info)

参数

object

要检查是否包含给定 info 字段的 DMatrix 对象。

info

要检查在 object 中是否存在或缺失的字段。

示例

x <- matrix(1:10, nrow = 5)
dm <- xgb.DMatrix(x, nthread = 1)

# 'dm' so far does not have any fields set
xgb.DMatrix.hasinfo(dm, "label")

# Fields can be added after construction
setinfo(dm, "label", 1:5)
xgb.DMatrix.hasinfo(dm, "label")