Reload and use a model

Every successful trained pipeline saves the best model in the result folder as photon_best_model.photon. To collaborate with other people share your trained model saved in this file. Have a look at the following example script if you want to reload the trained Hyperpipe:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from photonai.base import Hyperpipe
from sklearn.datasets import load_breast_cancer

X, _ = load_breast_cancer(True)

# After optimization is finished, PHOTONAI saves the user's pipeline
# fitted with the best hyperparameter configuration found
# as "photon_best_model.photon" in the project's result folder.
# this is done automatically, however the use may do so manually by calling
# my_pipe.save_optimum_pipe('/home/photon_user/photon_test/optimum_pipe.photon')

my_pipe = Hyperpipe.load_optimum_pipe("full_path/to/photon_best_model.photon")
predictions = my_pipe.predict(X)

# get permutation importances posthoc
reloaded_hyperpipe = Hyperpipe.reload_hyperpipe("full_path/to/results_folder/", X, y)
post_hoc_perm_importances = Hyperpipe.get_permutation_feature_importances(n_repeats=5, random_state=0)