跳到内容

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

用法

xgb.DMatrix.hasinfo(object, info)

参数

对象

要检查给定 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")