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

Fix pickling problem with closure in custom loss by using dill #36

Open
khsjursen opened this issue Jul 9, 2024 · 1 comment
Open
Labels
bug Something isn't working high priority on hold

Comments

@khsjursen
Copy link
Collaborator

When saving a grid search object with the custom XGBRegressor class and objective function, the following does not work:
joblib.dump(gs_obj, dir + '/' + 'custom_loss_cv_grid.pkl')

The custom objective function cannot be pickled since it is defined within a closure. Using dill instead of pickle solves the problem:

import dill as pickle

# Run grid search
gs_obj = GridSearchCV(..)

# Save grid search object
with open(dir + '/' + 'custom_loss_cv_grid.pkl', 'wb') as f:
    pickle.dump(gs_obj, f) 

Install with:
pip install dill

@khsjursen khsjursen added the bug Something isn't working label Jul 9, 2024
@JulianBiesheuvel JulianBiesheuvel added In Progress This issue is currently under investigation high priority labels Jul 16, 2024
@JulianBiesheuvel JulianBiesheuvel removed the In Progress This issue is currently under investigation label Aug 9, 2024
@JulianBiesheuvel
Copy link
Collaborator

Currently, this is implemented in the CustomXGBoostRegressor class directly. In addition, to loading a pre-existing model/gridsearch. Eventually, when more models are added this feature should be part of a wrapper class (or something similar).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority on hold
Projects
None yet
Development

No branches or pull requests

2 participants