python - 如何在 python 中对 PMML 模型进行超参数调整?
问题描述
我正在使用 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)
我正在使用 Python 中的以下代码加载保存的 RandomForest 模型
from pypmml import Model
rf = Model.fromFile('classification pmml file/random.pmml')
如何在 Python 中对此 RandomForest PMML 模型进行超参数调整?
解决方案
您可以像往常一样进行超参数调整;如果使用SkLearn2PMML包将生成的调谐管道转换为 PMML 表示,则无需执行任何特殊操作。
简而言之,如果您只调整一个估算器,那么只需将其包装GridSearchCV
到位。例如:
pipeline = PMMLPipeline([
("tuned-rf", GridSearchCV(RandomForestClassifier(..), param_grid = {..}))
])
pipeline.fit(X, y)
如果您正在调整多个估算器,那么您可以将GridSearchCV
其视为顶级工作流引擎,并将整个管道包装到其中。调整后的管道可以作为GridSearchCV.best_estimator_
属性获得:
pipeline = PMMLPipeline([
("rf", RandomForestClassifier(..))
])
gridsearch = GridSearchCV(pipeline, param_gird = {..})
gridsearch.fit(X, y)
pipeline = gridsearch.best_estimator_
更多详情,请参阅以下技术文章:https ://openscoring.io/blog/2019/12/25/converting_sklearn_gridsearchcv_pipeline_pmml/
推荐阅读
- r - R中带有ggplot2的自定义置信带?
- python-3.x - 如何使用漂亮的汤 python 获取文本?
- excel - SAP & Excel 错误 - SAP 试图在 Excel 中打开文件
- r - 在 R 中导入矩阵格式(.mtx)?
- javascript - 如何通过正则表达式模式匹配对字符串数组中的元素进行排序
- app-store-connect - How to set fastlane language to upload new app to itunesconnect
- c# - 更改同系列C#的颜色列
- reactjs - How to Use One handleChange Event for Multiple TextFields?
- android - 蓝牙音箱使用什么样的软件(例如 BOSE),您可以在外部对其进行修改吗?
- javascript - 如何从列表中为div对象jQuery动态设置坐标