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

标签 python machine-learning random-forest hyperparameters 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/

关于python - 如何在 python 中对 PMML 模型进行超参数调优?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59351591/

相关文章:

python - Pandas 在没有标题的表格中读取

使用Rascal分析和转换python源文件

python - Pybrain 神经网络阶跃传递函数

r - 随机森林混淆矩阵中的错误

RRF 模型给出的测试集 NA

R:绘制 OOB 错误率

python - 如何快速估计两个(纬度、经度)点之间的距离?

django中的Python多重继承函数覆盖和ListView

python - 如何在 scikit-learn 中使用 SGDRegressor

python - Keras 输入数据格式