Search code examples
picklepycaret

Is there a way to reduce down the size of the pickle file for PyCaret models?


I tried to compress a pickle file representing a PyCaret model.

import joblib
joblib.dump('my_file.pkl',  'new_file.pkl.z',compress=3)

The above code didn't work.

How can I reduce the size of a pickle file for PyCaret models?


Solution

  • There is no need to call the joblib.dump function yourself, you should call the PyCaret save function directly on the loaded model as follows:

    from pycaret.regression import load_model, save_model
    
    your_model = load_model('my_file.pkl')
    save_model(your_model, f'my_file.pkl', **{"compress":3})
    

    Example above is for a regression model

    For reference: Pycaret calls the jolib.dump function here passing any given kwargs.