skLearn2pmml带有pycaret模型到pmml的错误:对象不是superStimator的实例

发布于 2025-02-11 20:44:31 字数 1848 浏览 1 评论 0 原文

到目前为止,使用Pycaret创建模型(训练了许多不同的型号),但是当使用Catboost时,我无法保存到PMML。该代码与XGBoost和LightGBM一起使用相同的数据。

from sklearn2pmml.pipeline import PMMLPipeline
from sklearn2pmml import sklearn2pmml,make_pmml_pipeline
from pycaret.regression import setup,tune_model,finalize_model,create_model
    

clf=setup(data=df,
          target='target_Var',
          train_size= 0.8,
          fold_shuffle = True,
          fold = 5,
          fold_strategy="groupkfold",
          fold_groups="id",
          html = False,
          silent = True,
          session_id = 1,
          n_jobs = -1)

    model = create_model('catboost')
    tuned_model = tune_model(model, fold=5)
    final_model = finalize_model(tuned_model)
    model_pipeline = make_pmml_pipeline(final_model)
    sklearn2pmml(model_pipeline_pm, model_path)
        
             12     tuned_model = tune_model(model, fold=5)
             13     final_model = finalize_model(tuned_model)
        ---> 14     model_pipeline = make_pmml_pipeline(final_model)
        
        
        
        ~\Anaconda3\envs\cloned2\lib\site-packages\sklearn2pmml\__init__.py in make_pmml_pipeline(obj, active_fields, target_fields)
            138 
            139     """
        --> 140         steps = _filter_steps(_get_steps(obj))
            141         pipeline = PMMLPipeline(steps)
            142         if active_fields is not None:
        
        ~\Anaconda3\envs\cloned2\lib\site-packages\sklearn2pmml\__init__.py in _get_steps(obj)
             97                 return [("estimator", obj)]
             98         else:
        ---> 99                 raise TypeError("The object is not an instance of {0}".format(BaseEstimator.__name__))
            100 
            101 def _filter(obj):
        
        TypeError: The object is not an instance of BaseEstimator

creating a model using pycaret with no issue so far (trained a bunch of different models) but when using catboost, I cannot save to pmml. This very same code worked for xgboost and lightgbm with the same data.

from sklearn2pmml.pipeline import PMMLPipeline
from sklearn2pmml import sklearn2pmml,make_pmml_pipeline
from pycaret.regression import setup,tune_model,finalize_model,create_model
    

clf=setup(data=df,
          target='target_Var',
          train_size= 0.8,
          fold_shuffle = True,
          fold = 5,
          fold_strategy="groupkfold",
          fold_groups="id",
          html = False,
          silent = True,
          session_id = 1,
          n_jobs = -1)

    model = create_model('catboost')
    tuned_model = tune_model(model, fold=5)
    final_model = finalize_model(tuned_model)
    model_pipeline = make_pmml_pipeline(final_model)
    sklearn2pmml(model_pipeline_pm, model_path)
        
             12     tuned_model = tune_model(model, fold=5)
             13     final_model = finalize_model(tuned_model)
        ---> 14     model_pipeline = make_pmml_pipeline(final_model)
        
        
        
        ~\Anaconda3\envs\cloned2\lib\site-packages\sklearn2pmml\__init__.py in make_pmml_pipeline(obj, active_fields, target_fields)
            138 
            139     """
        --> 140         steps = _filter_steps(_get_steps(obj))
            141         pipeline = PMMLPipeline(steps)
            142         if active_fields is not None:
        
        ~\Anaconda3\envs\cloned2\lib\site-packages\sklearn2pmml\__init__.py in _get_steps(obj)
             97                 return [("estimator", obj)]
             98         else:
        ---> 99                 raise TypeError("The object is not an instance of {0}".format(BaseEstimator.__name__))
            100 
            101 def _filter(obj):
        
        TypeError: The object is not an instance of BaseEstimator

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无妨# 2025-02-18 20:44:31

您应该为CATBOST模型使用特定的导出方法:

if model == 'catboost' :
        final_model.save_model(path,format="pmml")

You should use specific export method for the catbost model:

if model == 'catboost' :
        final_model.save_model(path,format="pmml")
浪漫人生路 2025-02-18 20:44:31

请参阅jpmml-sklearn/sklearn2pmml堆栈支持的第三方套件的列表 -

从Sklearln2pmml 0.84(.2)中,lightgbm和Xgboost软件包在支持下列出,而Catboost套件则没有。

CATBOOST具有内置的PMML转换器(请参阅“ 应用PMML ”)。尝试将其集成到您的工作流程中。

See the list of 3rd party packages that are supported by the JPMML-SkLearn/SkLearn2PMML stack - https://github.com/jpmml/jpmml-sklearn#supported-packages

As of SkLearn2PMML 0.84(.2), the LightGBM and XGBoost packages are listed as supported, whereas the CatBoost package isn't.

CatBoost has built-in PMML converter (see "apply pmml"). Try to integrate this into your workflow instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文