Saving and loading models
by: Kevin Broløs & Chris Cave
(Feyn version 3.4.0 or newer)
Model
s can be saved to a file for use at a later time or place.
Note: Due to incompatibilities in the different versions of the
QLattice
in version 2.1, you are unable to load any models saved prior to version 2.1. If you need access to older models, we recommend you use a previous version offeyn
.
Example
Here is an example on how to save and load a model:
import feyn
from feyn.datasets import make_classification
# Generate a dataset and put it into a dataframe
train, test = make_classification()
# Instantiate a QLattice and run a classification simulation
ql = feyn.QLattice()
models = ql.auto_run(
data=train,
output_name='y'
)
# Save a model to a file
models[0].save('my_model.json')
You can load the Model
using feyn.Model.load.
from feyn import Model
model = Model.load('my_model.json')
prediction = model.predict(test)
Once a Model
is saved and selected, you can load them into any Python
environment to do predictions.
A loaded Model
is no different from a Model
sampled from the QLattice
. For example, you can resume fitting a Model
after loading it.