简体   繁体   English

如何在 python 中对 PMML 模型进行超参数调整?

[英]How can I do HyperParameter Tuning for PMML model in python?

I am creating a RandomForest PMML model using the following code in Python我正在使用 Python 中的以下代码创建一个 RandomForest PMML 模型

from sklearn2pmml.pipeline import PMMLPipeline
from sklearn2pmml import sklearn2pmml
rf=RandomForestClassifier()
rf = PMMLPipeline([('random',rf)])
rf.fit(X_train, y_train)
sklearn2pmml(rf, "classification pmml file/random.pmml",with_repr=True)

and I am loading the saved RandomForest Model using the following code in Python我正在使用 Python 中的以下代码加载保存的 RandomForest 模型

from pypmml import Model
rf = Model.fromFile('classification pmml file/random.pmml')

How can I do HyperParameter Tuning for this RandomForest PMML model in Python?如何在 Python 中对这个 RandomForest PMML 模型进行超参数调整?

You can do hyperparameter tuning as usual;您可以像往常一样进行超参数调整; there is no need to do anything special if the resulting tuned pipeline in converted to PMML representation using the SkLearn2PMML package.如果使用SkLearn2PMML包将生成的调整管道转换为 PMML 表示,则无需执行任何特殊操作。

In brief, if you're only tuning one estimator, then simply wrap it into GridSearchCV in place.简而言之,如果您只调整一个估算器,那么只需将其包装到GridSearchCV中即可。 For example:例如:

pipeline = PMMLPipeline([
  ("tuned-rf", GridSearchCV(RandomForestClassifier(..), param_grid = {..}))
])
pipeline.fit(X, y)

If you're tuning multiple estimators, then you can treat GridSearchCV as a top-level workflow engine, and wrap the whole pipeline into it.如果您正在调整多个估算器,那么您可以将GridSearchCV视为顶级工作流引擎,并将整个管道包装到其中。 The tuned pipeline can be obtained as the GridSearchCV.best_estimator_ attribute afterwards:调整后的管道可以作为GridSearchCV.best_estimator_属性之后获得:

pipeline = PMMLPipeline([
  ("rf", RandomForestClassifier(..))
])
gridsearch = GridSearchCV(pipeline, param_gird = {..})
gridsearch.fit(X, y)
pipeline = gridsearch.best_estimator_

For more details, see the following technical article: https://openscoring.io/blog/2019/12/25/converting_sklearn_gridsearchcv_pipeline_pmml/更多详情请看以下技术文章: https : //openscoring.io/blog/2019/12/25/converting_sklearn_gridsearchcv_pipeline_pmml/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM