AlexanderFabisch / gmr

Gaussian Mixture Regression
https://alexanderfabisch.github.io/gmr/
BSD 3-Clause "New" or "Revised" License
168 stars 49 forks source link

How to save fitted model? #21

Closed nikolai-neustroev closed 3 years ago

nikolai-neustroev commented 3 years ago

Hi!

Thanks a lot for maintaining this great library! It is really convenient and elegant.

I wonder if it is possible to save fitted model as a file?

AlexanderFabisch commented 3 years ago

Hi,

Thanks a lot for maintaining this great library! It is really convenient and elegant.

Thank you!

I wonder if it is possible to save fitted model as a file?

Python pickle works quite well for models that have to be stored only temporarily on a disk:

In [2]: %run examples/plot_estimate_gmm.py

...

In [3]: gmm
Out[3]: <gmr.gmm.GMM at 0x7f07316197d0>

In [4]: import pickle

In [5]: pickle.dump(gmm, open("file", "wb"))

In [6]: gmm2 = pickle.load(open("file", "rb"))

In [7]: gmm2
Out[7]: <gmr.gmm.GMM at 0x7f07213122d0>

If you want to archive your model for a longer time and have a representation that is independent of the underlyin library I would recommend to save the attributes GMM.priors, GMM.means, GMM.covariances in a format that you think is best suited for this. They are all pure numpy arrays, so this shouldn't be too difficult. There is no other information required to reconstruct the model.

AlexanderFabisch commented 3 years ago

@nikolai-neustroev I'll probably add this answer to the readme. Does it work for you?

nikolai-neustroev commented 3 years ago

@AlexanderFabisch yes, sure. thanks for help!