Interactive flow
by: Chris Cave
(Feyn version 3.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 Model
s 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.
import feyn
from sklearn.datasets import load_boston
import pandas as pd
from feyn.tools import split
#Download boston housing dataset
boston = load_boston()
df_boston = pd.DataFrame(boston.data, columns=boston.feature_names)
df_boston['PRICE'] = boston.target
# Train/test split
train, test = split(df_boston)
# Instantiate a QLattice
ql = feyn.QLattice()
models = ql.auto_run(
data=train,
output_name='PRICE'
)
# 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. The 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 you 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
Feyn
Location in 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])