Feyn Documentation

Feyn Documentation

  • Learn
  • Guides
  • Tutorials
  • API Reference
  • FAQ

›Understand Your Models

Getting Started

  • Quick start
  • Using Feyn
  • Installation
  • What is the QLattice?

Essentials

  • Auto Run
  • Summary plot
  • Plot response
  • Splitting a dataset
  • Seeding a QLattice
  • Predicting with a model
  • Saving and loading models
  • Categorical features

Evaluate Regressors

  • Regression plot
  • Residuals plot

Evaluate Classifiers

  • ROC curve
  • Confusion matrix
  • Plot probability scores

Understand Your Models

  • Plot response 1D
  • Plot response 2D
  • Model signal
  • Segmented loss
  • Interactive flow

Primitive Operations

  • Using the primitives
  • Updating priors
  • Sample models
  • Fitting models
  • Pruning models
  • Visualise a model
  • Diverse models
  • Updating a QLattice
  • Validate data
  • Semantic types

Advanced

  • Converting a model to SymPy
  • Logging in Feyn
  • Setting themes
  • Saving a graph as an image
  • Using the query language
  • Estimating priors
  • Filtering models
  • Model parameters
  • Model complexity

Privacy & Commercial

  • Privacy
  • Community edition
  • Commercial use
  • Transition to Feyn 3.0

Interactive flow

by: Kevin Broløs and Chris Cave
(Feyn version 3.1.0 or newer)


The output value of a node within a neural network of a given data point is called the activation value. Usually neural networks are dense with many nodes so it can be difficult to decipher what a particular activation value at a given node can mean in the overall picture of the model. The Models from the QLattice are much less dense than a neural network which means that the activation values are much easier to decode.

This gives the benefit that one can interpret how each activation value affects the output and thus how each feature contributes to the model. This is what the method plot_flow and plot_flow_interactive captures.

Example

import feyn

from sklearn.datasets import load_diabetes
import pandas as pd

from feyn.tools import split

# Load into a pandas dataframe
dataset = load_diabetes()
df_diabetes = pd.DataFrame(dataset.data, columns=dataset.feature_names)
df_diabetes['response'] = dataset.target

# Train/test split
train, test = split(df_diabetes)

# Instantiate a QLattice
ql = feyn.QLattice()

models = ql.auto_run(
    data=train,
    output_name='response'
)
# Select the best Model
best = models[0]

best.plot_flow(
    data=train,
    sample=train.iloc[0:1]
)

The method plot_flow takes a single sample and plots the activation values at each node. It displays these value above each node.

Interactive mode

The experimental method interactive_activation_flow uses plot_flow and make this interactive as in the image below.

from feyn.plots.interactive import interactive_activation_flow

interactive_activation_flow(best, train)

As with all models one should be very careful when they investigate how the Model behaves outside the domain it has been trained on. This could given unusual and unexpected results which would need further investigation.

This tool is only for IPython kernels. This requires installing ipywidgets and enabling the extension in jupyter notebook:

$ jupyter nbextension enable --py widgetsnbextension

or in jupyter lab:

$ jupyter labextension install @jupyter-widgets/jupyterlab-manager

Parameters of plot_flow

data

This should be the data the model has trained on.

sample

The single sample you want to visualize.

filename

Use to specify a path to a file to save the plot to (as SVG).

best.plot_flow(
    data=train,
    sample=train.iloc[0:1],
    filename='flow.svg'
)

Note that the interactive version does not support saving to file - you can instead use the non-interactive version for this purpose. It also does not take the sample as a parameter.

Location in Feyn

This function can also be found in feyn.plots module.

from feyn.plots import plot_activation_flow

plot_activation_flow(best, train, train.iloc[0:1])
← Segmented lossUsing the primitives →
  • Example
    • Interactive mode
  • Parameters of plot_flow
    • data
    • sample
    • filename
  • Location in Feyn

Subscribe to get news about Feyn and the QLattice.

You can opt out at any time, and you can read our privacy policy here.

Copyright © 2024 Abzu.ai - Feyn license: CC BY-NC-ND 4.0
Feyn®, QGraph®, and the QLattice® are registered trademarks of Abzu®