Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pickle Gama object #125

Open
jimgoo opened this issue Sep 23, 2021 · 2 comments
Open

Can't pickle Gama object #125

jimgoo opened this issue Sep 23, 2021 · 2 comments
Labels
enhancement An improvement to an existing component, e.g. optimization.
Milestone

Comments

@jimgoo
Copy link

jimgoo commented Sep 23, 2021

Is there a way to save and load the GamaClassifier and GamaRegressor objects? When I try to save them with pickle using this:

clf = GammaClassifier(...)

with open('model.pkl', 'wb') as f:
    pickle.dump(clf, f)

I get:

AttributeError: Can't pickle local object 'AsyncEA.__init__.<locals>.get_parent'

Thanks!

@jimgoo jimgoo changed the title Saving and loading Gama object Saving and loading GamaClassifier object Sep 23, 2021
@PGijsbers
Copy link
Member

Hi, sorry for the delay!
I use some locally defined functions (including some lambdas), which prevents gama objects from being pickled easily. Out of curiosity, why do you want to save the entire gama object as opposed e.g. its final model?

You can pickle the final model instead:

clf = GamaClassifier(...)
clf.fit(x, y)

with open("model.pkl", "wb") as f:
    pickle.dump(clf.model, f)

However gama is not too far off from being entirely pickleable, I created a branch pickle which allows for the gama object to be pickled. I don't entirely like the introduced top-level functions so I am not quite ready to merge it into master yet, but it should work for your purpose if you want to use it.

I'll leave the issue open until gama supports pickle directly (or we explicitly agree not to)

@PGijsbers PGijsbers changed the title Saving and loading GamaClassifier object Can't pickle Gama object Oct 15, 2021
@PGijsbers PGijsbers added the enhancement An improvement to an existing component, e.g. optimization. label Oct 15, 2021
@jimgoo
Copy link
Author

jimgoo commented Nov 23, 2021

Ah ok great, saving and loading the final model works for me.

Thanks!

@PGijsbers PGijsbers added this to the v22.1+ milestone Jul 27, 2022
@PGijsbers PGijsbers modified the milestones: v22.1+, v22.1 Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement to an existing component, e.g. optimization.
Projects
None yet
Development

No branches or pull requests

2 participants