Search code examples
pythonscikit-learnpycaret

sklearn2pmml error with pycaret model to pmml : 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

Solution

  • You should use specific export method for the catbost model:

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