xgboost icon indicating copy to clipboard operation
xgboost copied to clipboard

Split MetaInfo During CV

Open BlindApe opened this issue 12 years ago • 6 comments

After this issue: https://github.com/tqchen/xgboost/issues/83

I'm trying to find a workaround to this problem: My model fits desegregated cases but the metric error needs merging all cases of the same item code and computing a weighted metric at item code level.

If I don't use 'base_margin' slot, could I use it for this purpose? Or if I set any info in this slot xgboost use it as base margin automatically?

In case the answer be NO. Any tip to workaround? Could be possible to introduce an 'id' and 'merging_group' slots for future versions?

Thank you!

BlindApe avatar Oct 01 '14 12:10 BlindApe

Thanks for bring this issue up. You cannot use base_margin, since it is used for generating prediction.

Here is a solution which I think fits your need, see updated version of example https://github.com/tqchen/xgboost/blob/master/R-package/demo/custom_objective.R

tqchen avatar Oct 01 '14 16:10 tqchen

For train and a hold data set is easy setting the attr to each DMatrix. For CV methods is needed modify the xgb.cv.mknfold function for set the attr to each fold data sets (train and test). This is a bit less elegant but works. Thanks.

BlindApe avatar Oct 01 '14 17:10 BlindApe

The advantage of doing things in this way is that you can put arbitrary attributes along with instance with no modification of the DMatrix so it is good for extending various ideas.

For the cv, I suppose we can change mknfold to automatically split all the attributes that are vector, like you mentioned, which will solves the problem for all vector type attributes?

tqchen avatar Oct 01 '14 17:10 tqchen

Sorry, I think the update should be slice in https://github.com/tqchen/xgboost/blob/master/R-package/R/slice.xgb.DMatrix.R

@hetong007 can you look into it?

tqchen avatar Oct 01 '14 18:10 tqchen

Yes, this would be very useful.

BlindApe avatar Oct 01 '14 18:10 BlindApe

Finally it is fixed in this commit.

Please test it with the following code:

require(xgboost)
data(agaricus.train, package='xgboost')
dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
attr(dtrain, 'test') <- getinfo(dtrain, 'label')
str(attributes(dtrain))
slice(dtrain,1:20)

hetong007 avatar Jan 25 '15 22:01 hetong007