Как конвертировать модель Python xgboost в pmml? - PullRequest
0 голосов
/ 10 января 2019

Как конвертировать модель Python xgboost в 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_

Ответы [ 2 ]

0 голосов
/ 14 января 2019
Standard error:
    sklearn2pmml(tuner.best_estimator_,'xgbregressor_pipeline.pmml')
java.lang.UnsupportedClassVersionError: org/jpmml/sklearn/Main : Unsupported major.minor version 52.0
  File "C:\ProgramData\Anaconda3\lib\site-packages\sklearn2pmml\__init__.py", line 246, in sklearn2pmml
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    raise RuntimeError("The JPMML-SkLearn conversion application has failed. The Java executable should have printed more information about the failure into its standard output and/or standard error streams")
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
RuntimeError: The JPMML-SkLearn conversion application has failed. The Java executable should have printed more information about the failure into its standard output and/or standard error streams
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Exception in thread "main" 
0 голосов
/ 10 января 2019

См. Пакет SkLear2PMML: https://github.com/jpmml/sklearn2pmml

Сначала определите новый конвейер pmml и вставьте в него свой XGBRegressor. Затем установите конвейер pmml, используя ученик GridSearchCV. Наконец, экспортируйте GridSearchCV.best_estimator_ - который должен быть оптимизированным конвейером pmml - в формат данных PMML, используя вызов функции sklearn2pmml.sklearn2pmml:

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

Также см. Слайд № 26 следующей презентации: https://www.slideshare.net/VilluRuusmann/converting-scikitlearn-to-pmml

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...