by: Kevin Broløs
(Feyn version 1.4 or newer)
Once you've evaluated your graphs and are ready to use these predictions in a production setup, you can simply save the graphs.
from sklearn.datasets import make_classification import pandas as pd from feyn import QLattice from feyn.tools import split ql = QLattice() # Generate a dataset and put it into a dataframe X, y = make_classification() data = pd.DataFrame(X, columns=[str(i) for i in range(X.shape)]) data['target'] = y # Train/test split train, test = split(data) # Get a classifier qgraph = ql.get_classifier(train, 'target') qgraph.fit(train) # Select a graph from your fitted QGraph best_graph = qgraph.best() # Save your evaluated graph to a file best_graph.save('/tmp/my_precious.graph')
And that's that. You can load the graphs again at any time using feyn.Graph.load, and use them to predict on new data.
from feyn import Graph from feyn.plots import plot_confusion_matrix loaded_graph = Graph.load('/tmp/my_precious.graph') prediction = loaded_graph.predict(test) plot_confusion_matrix(y_true=test['target'], y_pred=prediction.round(), title="Confusion Matrix [Test]")
Once a graph is saved and selected, you can insert them into any (
Python) environment to do predictions - you don't need access to your
QLattice in order to use the resulting graphs.
You can even do fine-tuning or fitting of that specific graph after loading it, if you want to!