You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there isn't a way to do this, no. It seems a very sensible thing to allow though. I think it would require each type of model (GPFlow, sckit-learn and keras) having save and load methods that the Emulator can then just use.
I will flag this as a feature request and try to implement it when I have a chance but would also be very happy to review pull-requests that implement it.
In the meantime, for the random forest model (only) I think you should be able to just use pickle:
@duncanwp It seems like the esem random forest is a simple implementation of the scikit-learn random forest. In the meantime, would you recommend training my emulator with scikit-learn and saving the model using pickle?
It's also possible (but a little convoluted currently) to wrap the loaded model back in to ESEm:
# Save the sklearn model held internally in the esem wrapperwithopen("rf_model.pkl","wb") asf:
pickle.dump(esem_rf_model.model.model, f)
# Load it againwithopen("rf_model.pkl","rb") asf:
skmodel=pickle.load(f)
# Wrap the loaded modelfromesem.wrappersimportwrap_datafromesem.data_processorsimportFlattenfromesem.model_adaptorimportSKLearnModelfromesem.emulatorimportEmulatorfromsklearn.ensembleimportRandomForestRegressorwrapped_skmodel=SKLearnModel(skmodel)
# Note that we need to reload the data seperately (this is used internally for post-processing)data=wrap_data(y_train, data_processors=[Flatten()])
loaded_esem_rf_model=Emulator(wrapped_skmodel, x_train, data)
loaded_esem_rf_model.predict(...)
Thanks @duncanwp ! I managed to save a RF model. I'll leave this issue open in case you want this as documentation for a feature request. Otherwise, feel free to close. Thanks again!
Hi there @duncanwp thanks for that work around. Just bumping this thread that this would be great to have! I was able to use your workaround for a GPFlow model, but it would be great to have this as method of an Emulator object too!
Hi @adrifoster , part of the reason this stalled was because it didn't seem to work for tensor flow based emulators - did you find it worked OK for the GPFLow one though?
Activity
duncanwp commentedon Feb 18, 2022
Thanks!
Currently there isn't a way to do this, no. It seems a very sensible thing to allow though. I think it would require each type of model (GPFlow, sckit-learn and keras) having
saveandloadmethods that theEmulatorcan then just use.I will flag this as a feature request and try to implement it when I have a chance but would also be very happy to review pull-requests that implement it.
In the meantime, for the random forest model (only) I think you should be able to just use pickle:
EricKeenan commentedon Feb 18, 2022
Thanks for the reply.
That solution doesn't appear to work in my case
Likewise with
duncanwp commentedon Feb 18, 2022
Ah OK, that's because of some of the
tensorflowfunctions on theEmulator... This will need a bit more thought sorry.EricKeenan commentedon Feb 22, 2022
@duncanwp It seems like the
esemrandom forest is a simple implementation of thescikit-learnrandom forest. In the meantime, would you recommend training my emulator withscikit-learnand saving the model using pickle?duncanwp commentedon Feb 23, 2022
Yes, you're absolutely right.
It's also possible (but a little convoluted currently) to wrap the loaded model back in to ESEm:
I made a full example here: https://gist.github.com/duncanwp/e4b96690da5bb0bf2505bb94d5450001
EricKeenan commentedon Mar 1, 2022
Thanks @duncanwp ! I managed to save a RF model. I'll leave this issue open in case you want this as documentation for a feature request. Otherwise, feel free to close. Thanks again!
adrifoster commentedon Aug 5, 2024
Hi there @duncanwp thanks for that work around. Just bumping this thread that this would be great to have! I was able to use your workaround for a GPFlow model, but it would be great to have this as method of an Emulator object too!
duncanwp commentedon Aug 6, 2024
Hi @adrifoster , part of the reason this stalled was because it didn't seem to work for tensor flow based emulators - did you find it worked OK for the GPFLow one though?