What is the best way to save a sklearn model?

I am working on a python desktop application. This app makes some predictions. Right now I am training my sklearn model with a python script, storing the model parameters as a dictionary in the yaml file. Then I create this yaml in my python application. Then, when I use the application, the model is recreated using the parameters from the dictionary. I realized that people who have another version of sklearn get an error. I tried to save my model in a pickle file, but in this case some warning was made when the application was launched on a machine with a different version of sklearn.

+4
source share
2 answers

There is no guarantee that this sklearn model will be compatible between sklearn versions. Indeed, an implementation or internal API may vary between versions. More info here .

If you consider one version, the best way is to disassemble and not save the parameters in the yaml file. Better yet, use joblib for this. Read more about here .

+4
source

I realized that people who have another version of sklearn get an error.

In this case, create Python sandboxes using virtualenvs

+4
source

Source: https://habr.com/ru/post/1686978/


All Articles