# Using a Graph

by: Kevin Broløs

The `graph`

is the final artifact, and can be referred to as your output `model`

to keep in line with other machine learning frameworks.

A `graph`

consists of one or more of your input features, some `interactions`

between them and a variety of functions that have been fitted to your dataset, leading to an output.

An example `graph`

for the iris dataset could look like this:

In an IPython environment, you'll be able to hover over each of the `interactions`

to get a tooltip with the internal state of it - such as the weights, biases and encodings.

## Evaluate, evaluate, EVALUATE!!!

Once you've selected a graph, you will want to evaluate it, and use it to produce predictions.

```
from feyn import tools
# Select a graph from your fitted QGraph
best_graph = qgraph.sort(train)[0]
# Get predictions
prediction = best_graph.predict(test)
tools.plot_confusion_matrix(y_true=test['target'],
y_pred=prediction.round(),
title="Confusion Matrix [Test]")
```

## I'm saving this one for later!

Once you've evaluated your `graphs`

and are ready to use these predictions in a production setup, you can simply save the `graphs`

.

```
# 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
loaded_graph = Graph.load('/tmp/my_precious.graph')
prediction = loaded_graph.predict(test)
tools.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`

.