jpmml / r2pmml

R library for converting R models to PMML
GNU Affero General Public License v3.0
73 stars 18 forks source link

Generating xgboost feature map for factor columns #12

Closed dandan0503 closed 7 years ago

dandan0503 commented 7 years ago

hai, when i use r2pmml in xgboost,i don't know if my feature's type is factor,what the "type" i can write?

data.fmap = data.frame(
  "id" = seq(from = 0, (to = ncol(good_approve_user[,2:47]) - 1)),
  "name" = names(good_approve_user[,2:47]),
  "type" = rep("q", ncol(good_approve_user[,2:47]))
)
r2pmml(bst, fmap = data.fmap, missing = NA,'data.pmml')

when "type" is 'q',in java ,i find it is float,but my feature has "string" as factor,how can i write?

vruusmann commented 7 years ago

The factor type is i. For example, a factor color["red", "yellow", "green"] should be encoded as:

id  name    type
1   color=red   i
2   color=yellow    i
3   color=green i

The JPMML-XGBoost project provides an R utility method genFMap() for generating feature map files based on an R data.frame object: https://github.com/jpmml/jpmml-xgboost/blob/master/src/main/R/util.R#L3

dandan0503 commented 7 years ago

thank you very much~~