How to convert python xgboost model into the pmml?

Viewed 5849

How to convert python xgboost model into the pmml ?

reg = XGBRegressor(learning_rate=0.1, n_estimators=30, max_depth=4, min_child_weight=4, gamma=0.1,
                       subsample=0.9, colsample_bytree=0.8, objective='binary:logistic', reg_alpha=1,
                       scale_pos_weight=1, seed=27)
param_test = [{
        'max_depth': [i for i in range(1, 3)],
        'gamma': [i / 10.0 for i in range(0, 10)],
        'n_estimators': [i for i in range(2, 14, 2)],
}]
gsearch = GridSearchCV(reg, param_grid=param_test, scoring='neg_mean_squared_error', n_jobs=4, iid=False, cv=5)
gsearch.fit(x_train, y_train)
best_model = gsearch.best_estimator_
1 Answers

See the SkLear2PMML package: https://github.com/jpmml/sklearn2pmml

First, define a new pmml pipeline, and insert your XGBRegressor into it. Then, fit the pmml pipeline using the GridSearchCV learner. Finally, export the GridSearchCV.best_estimator_ - which shall be the optimized pmml pipeline - into PMML data format using the sklearn2pmml.sklearn2pmml function call:

pmml_pipeline = PMMLPipeline([
  ("regressor", XGBRegressor())
])
tuner = GridSearchCV(pmml_pipeline, ...)
tuner.fit(X, y)
sklearn2pmml(tuner.best_estimator_, "xgbregressor-pipeline.pmml")

Also see slide #26 of the following presentation: https://www.slideshare.net/VilluRuusmann/converting-scikitlearn-to-pmml

Related