I'm trying to create a custom evaluation metric (feval) function for xgboost.cv. It should process some of the training features, however I can't find a way to extract features from xgboost.DMatrix() object (only labels)..

As I was suggested it can be done with first making a DMatrix slice then saving it to a svmlight file and finally reading it with scikit-learn, but is there a more elegant way if doing it?


You can convert DMatrix to NumPy array using dmatrix2np:

from dmatrix2np import dmatrix_to_numpy

converted_np_array = dmatrix_to_numpy(dmatrix)

It's open-source, you can see its code here.


Currently we cannot direct extract data matrix from DMatrix, mainly due to DMatrix is a internal data structure that may or maynot sit in memory.

--by tqchen commented on 3 Aug 2015



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.