Accessing QID's from a DMatrix

I’d like to be able to retrieve the qid’s from a dmatrix in a custom objective function, however, there’s no direct access, and there’s no getter, i’ve tried:

dm = xgb.DMatrix([[1, 2], [1, 2], [3, 4]], [1, 1, 0], qid=[1, 1, 2])
dm.get_uint_info('qid')

but that gives:
data.cc:581: Unknown uint32 field name: qid

what am i missing?

1 Like

answering my own question: i realized that

dm.get_group()

still works, and this can be used to reproduce a set of query ids like:

    groups = dm.get_group()
    qids = reduce(lambda acc, x : acc + [x[0]]*x[1], enumerate(groups), [])
1 Like