fabsig / GPBoost

Combining tree-boosting with Gaussian process and mixed effects models
Other
574 stars 46 forks source link

load from model_file is not always working #147

Closed thugentobler closed 1 month ago

thugentobler commented 1 month ago

Hi Fabio I'm currently working with your package in python for my master thesis. And i stumbled upon an issue, where I can't load a model after saving it to json. There seems to be two different json generated when saving, but I have not figured out when which one gets saved. One starts with {"has_gp_model": 1, "booster_str: ... rho50_iter222_gaussian_model_gpb.json and the other one with {"learner": {"attributes":{}, ... rho10_iter0_gaussian_model_gpb.json. I'm quite certain, both of the boosters I tried to save have a gpmodel with them. And when i try to load the latter json, there is an error:

in Booster.__init__(self, params, train_set, model_file, model_str, silent, gp_model)
   [2454]        elif i > 1:
   [2455]            break
-> [2456]  if has_gp_model == '"has_gp_model": 1,\n' or has_gp_model == ' "has_gp_model": 1,\n':
   [2457]         self.has_gp_model = True
   [2458]         with open(model_file, "r") as f:

UnboundLocalError: cannot access local variable 'has_gp_model' where it is not associated with a value

Perhaps there is something missing in the docs but it seems strange that the one json can't be loaded again. Thanks for looking into it. Best Tobias

fabsig commented 1 month ago

Thank you for using GPBoost!

Can you please provide a reproducible example (eg using simulated data)?

thugentobler commented 1 month ago

I'm sorry, it was a mistake on my side. It is all good with your code