将PMML模型导入Python(Scikit-learn) [英] Importing PMML models into Python (Scikit-learn)

查看:602
本文介绍了将PMML模型导入Python(Scikit-learn)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从scikit-learn导出PMML模型似乎有一些选择,例如sklearn2pmml,但是在相反方向上的信息要少得多.我的案例是一个以前在R中内置的XGboost模型,并使用r2pmml保存到了PMML,我想在Python中使用它. Scikit通常使用pickle来保存/加载模型,但是也可以使用PMML将模型导入scikit-learn中吗?

There seem to be a few options for exporting PMML models out of scikit-learn, such as sklearn2pmml, but a lot less information going in the other direction. My case is an XGboost model previously built in R, and saved to PMML using r2pmml, that I would like to use in Python. Scikit normally uses pickle to save/load models, but is it also possible to import models into scikit-learn using PMML?

推荐答案

您不能在通用表示形式(例如PMML)上连接不同的专用表示形式(例如R和Scikit-Learn本机数据结构).尝试将R数据结构直接转换为Scikit-Learn数据结构可能会更好.

You can't connect different specialized representations (such as R and Scikit-Learn native data structures) over a generalized representation (such as PMML). You may have better luck trying to translate R data structures to Scikit-Learn data structures directly.

XGBoost实际上是上述规则的一个例外,因为它的R和Scikit-Learn实现只是本地XGBoost库的薄包装.在经过训练的R XGBoost对象中,有一个斑点raw,它是其本机XGBoost表示形式的模型.将其保存到文件中,然后使用xgb.Booster.load_model(fname)方法加载到Python中.

XGBoost is really an exception to the above rule, because its R and Scikit-Learn implementations are just thin wrappers around the native XGBoost library. Inside a trained R XGBoost object there's a blob raw, which is the model in its native XGBoost representation. Save it to a file, and load in Python using the xgb.Booster.load_model(fname) method.

如果您知道需要在Scikit-Learn中部署XGBoost模型,那么为什么要在R中对其进行训练?

If you know that you need to the deploy XGBoost model in Scikit-Learn, then why do you train it in R?

这篇关于将PMML模型导入Python(Scikit-learn)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆