if (FALSE) {
# Example using the xgboost package example model.
library(xgboost)
data(agaricus.train, package = "xgboost")
data(agaricus.test, package = "xgboost")
train <- agaricus.train
test <- agaricus.test
model1 <- xgb.train(
params = list(max_depth = 2, eta = 1, objective = "binary:logistic"),
data = xgb.DMatrix(train$data, label = train$label),
nthread = 2, nrounds = 2
)
# Save the tree information in an external file:
xgb.dump(model1, "model1.dumped.trees")
# Convert to PMML:
model1_pmml <- pmml(model1,
input_feature_names = colnames(train$data),
output_label_name = "prediction1",
output_categories = c("0", "1"),
xgb_dump_file = "model1.dumped.trees"
)
# Multinomial model using iris data:
model2 <- xgb.train(
params = list(max_depth = 2, eta = 1, objective = "multi:softprob", num_class = 3),
data = xgb.DMatrix(as.matrix(iris[, 1:4]), label = as.numeric(iris[, 5]) - 1),
nthread = 2, nrounds = 2
)
# Save the tree information in an external file:
xgb.dump(model2, "model2.dumped.trees")
# Convert to PMML:
model2_pmml <- pmml(model2,
input_feature_names = colnames(as.matrix(iris[, 1:4])),
output_label_name = "Species",
output_categories = c(1, 2, 3), xgb_dump_file = "model2.dumped.trees"
)
}
Run the code above in your browser using DataLab