1

I try to use xgboost in R to get rules (gbtree) from my data, so I can use the rules in an other system (not predicted data with 'predict'). The Input-Data have appr. 1500 colums and 40 Mio rows with binary, sparse data and the Label is a binary column, too.

library(xgboost)
library(Matrix)

labels <- data.frame(labels = sample.int(2, m*1, TRUE)-1L)
observations <- Matrix(as.matrix(data.frame(feat_01=sample.int(2, size=100, T) -1,
                                            feat_02=sample.int(2, size=100, T) -1,
                                            feat_03=sample.int(2, size=100, T) -1,
                                            feat_04=sample.int(2, size=100, T) -1,
                                            feat_05=sample.int(2, size=100, T) -1)), sparse=T)

dtrain <- xgb.DMatrix(data = observations, label = labels$labels)

bstResult <- xgb.train(data = dtrain, 
                       nthread = 1, 
                       nround = 4, 
                       max_depth = 3, 
                       verbose = T,
                       objective = "binary:logistic",
                       booster='gbtree')

xgb.dump(bstResult)
xgb.plot.tree(model = bstResult, n_first_tree = 2)

I visualize the data as xgb.dump or xgb.plot.tree. But I need the data in a form like:

rule1: feat_01 == 1 & feat_02==1 & feat_03== 0 --> Label = 1

rule2: feat_01== 0 & feat_03==1 & feat_04== 1 --> Label = 0

Is this possible or am I on the wrong track?

Regards Heiko

edit: added example and tried to make the question better

user2083142
  • 431
  • 1
  • 6
  • 16
  • When asking for help, you should provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample data and code we can run. This will make it easier to help you. – MrFlick Mar 09 '17 at 15:47

1 Answers1

0

On one hand, I think you can use the importance matrix to obtain the coverage and ranking of each feature. On the other hand, xgboost uses an ensemble of weak learners using bagging, the rules should be 'rare'

Mario
  • 5
  • 1
  • Does it mean, I can learn a model from my data and just use it with 'predict ' in R itself? With C5.0 I could get the rules, but it is very slow. – user2083142 Mar 10 '17 at 13:54