by: Tom Jelen
Feyn version: 1.2.+
In order to deploy a
Graph that you have trained with Feyn, you simply just need to save it to a file. Then from the machine (or agent) where you want to use this
Graph for doing predictions, you just load it again from the file via Feyn.
This notebook shows how to use
Graph.load to take a
Graph and promote it to a production environment.
This notebook will not go into the details of how build and teach Feyn-models. If that is of your interest, then take a look at some of the other notebooks.
import numpy as np import pandas as pd import feyn from feyn.tools import plot_confusion_matrix, split
data = pd.read_csv('pulsar_stars.csv') train, test = split(data)
Create a Feyn-model from the pulsar stars dataset
This happens on a machine that is running a training process.
The quality of this model is not important for this tutorial, so we won't spend a lot of time fitting the graph.
qlattice = feyn.QLattice() qgraph = qlattice.get_qgraph(data, "out_target_class") qgraph.fit(train)
QGraph (depth<=5) <cache: 1999>
Select and promote a graph
Once a suitable graph has been selected (human selection, or maybe just purely based on statistics), you need to save it somewhere, so that it can be picked up by your process that executes it to do predictions.
For this demo we will just use a temporary file, but it can be saved to any file- or path-like object.
production_database_file = '/tmp/pulsar-stars.graph' best_graph = qgraph.sort(train) best_graph.save(production_database_file)
In your production environment, you have a process or an interface that uses the
Graph to execute predictions. It can use the
Graph.load function to load the previously saved
best_graph = feyn.Graph.load(production_database_file) prediction = best_graph.predict(test) plot_confusion_matrix(y_true=test['out_target_class'], y_pred=prediction.round(), title="Confusion Matrix [Test]")