# NOT RUN {
# 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 <- xgboost(
data = train$data, label = train$label,
max_depth = 2, eta = 1, nthread = 2,
nrounds = 2, objective = "binary:logistic"
)
# 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 <- xgboost(
data = as.matrix(iris[, 1:4]),
label = as.numeric(iris[, 5]) - 1,
max_depth = 2, eta = 1, nthread = 2, nrounds = 2,
objective = "multi:softprob", num_class = 3
)
# 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"
)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab