Opening the black box

Explainable AI with the QLattice and feynplots

Horizontal rule

Oh, hi! This blog post was written with a version of Feyn® earlier than 2.0.0. Results may vary! To stay up to date with the latest version of Feyn and all its functions, check out the Feyn changelog. If you'd like to recreate this with a newer version of Feyn and have questions, you can always use our Discord channel for community QLattice® support or contact an Abzoid for commercial QLattice support.

Horizontal rule
A neural network: Has it got it going on?
A neural network: Has it got it going on?

When we have even a simple neural network like this, it’s a bit tricky to know what’s going on.

Each of these nodes have three to four inputs, so we can’t really visualise the innards in a satisfying way.

However it is much easier to see the inner workings from a graph that comes from a QLattice.

Horizontal rule

Graphs from the QLattice have nodes (which we call interactions) and edges between interactions. The graphs have inputs and an output with a natural flow from left to right.

Let’s take an example! We will use the Wisconsin breast cancer dataset. This has thirty numerical features and a target feature called diagnosis. Either the tumor has been classified as benign (value 0) or malignant (value 1).

QLattice graph

What are we looking at here? The tanh function takes the two features, one called concave points worst and the other called perimeter mean, which correspond to the little x1 and x0 on the tanh function.

The weights on the tanh function, w0 and w1, correspond to the variables of x0 and x1. This means that the output of the function is:

tanh( w0×x0 + w1×x1 + bias)

That’s all the graph does. The output of this function is the predict of the diagnostic on this dataset. We have two inputs and an output, so we can now make a plot!

QLattice plot

There’s a few things that need to be explained in the plot:

  • Each dot corresponds to a datapoint in the training set. The colour corresponds to the actual value of the target variable. In this case yellow corresponds to 1 (malignant) and purple to 0 (benign);
  • The x-axis corresponds to the variable x0;
  • The y-axis corresponds to the variable x1;
  • The scale on each axis the scale of each feature;
  • The lines correspond to the value of the output at the (x0,x1) coordinate. If a point lies on a line which has a value of, for example, 0.15 it means that the output of that tanh function at that point is equal to 0.15;
  • There’s a hidden standardisation going on here. The variables x0 and x1 correspond to the standardised features perimeter mean and concave points worst respectively. This means that the output of the tanh function is in fact evaluated at the standardised points. If this is a little confusing then don’t worry about it, we will discuss this at a later blog post point.

You can see from this model, it’s taking only perimeter mean and concrete points worst and then splits the data just using this. This loss is fairly ok but we can definitely do a bit better.

Horizontal rule

Let’s take a look at a more complicated graph but with a lower loss.

QLattice model

The two functions on the left hand side take the features as input and then outputs a value between -1 and 1. Then the function on the right hand side takes in these values between -1 and 1 and outputs a value within the feature range of diagnosis, which is 0 and 1.

Let’s take a look at the charts.

QLattice chart
QLattice chart
QLattice chart

As you can see, this graph takes four features :radius worst, perimeter se, concavity worst, and concavity se. This time instead of just separating by concavity worse and perimeter mean, it’s found a better model that multiplies concavity worst and concavity se and then splits with respect to a tanh regression on radius worst and perimeter se.

Horizontal rule

This also works with regression problems. Let’s look at the California housing dataset. In this dataset there are eight features to predict the price of a house. Here’s a particular graph:

QLattice model

And here’s the collection of charts associated with it.

QLattice plot
QLattice plot
QLattice plot
QLattice plot
QLattice plots
QLattice plot
QLattice plot

Now instead of splitting the dataset into two clusters this time, the model turns it into a regression from low prices (purple dots) to high prices (yellow dots).

In this case there are interactions that take only one variable. The plots for these will have the input on the x-axis and the output on the y-axis.

Here is the summary of the code for the California housing dataset.

This package is available on my personal github page and can be found on pypi.

If you want to sign up and play with your own QLattice where you can you use a package like this, get a free community QLattice!

Contributors

  • Chris Cave, Mathematician

    Chris holds a PhD in Mathematics from the University of Southampton. He works on strengthening the mathematical framework of Abzu’s core AI and machine learning technology and has a leading role in applied predictive analysis. Chris is an award-winning rower and giggler.
  • Elyse Sims, Marketing + Communication

    Elyse holds an EMBA from Georgia State University and wrangles Marketing and Communication for Abzu. She has 11+ years’ international marketing experience and prefers fast-paced startup environments. Elyse is an avid runner, CrossFit-er, gardener, reader, and swearer.

Newsletter sign up

Hi, Chris and Elyse here! If you want to learn more about the QLattice, debate the use of the Oxford comma, or some other third thing, then sign up for our newsletter!