Skip to content


Repository files navigation

GraphSVX: Shapley Value Explanations for Graph Neural Networks

This repository contains the source code for the paper GraphSVX: Shapley Value Explanations for Graph Neural Networks_, by Alexandre Duval and Fragkiskos Malliaros - accepted at the European Conference on Machine Learning and Principles and Practice of Knowledge Discovery in Databases (ECML PKDD) 2021.


Graph Neural Networks (GNNs) achieve significant performance for various learning tasks on geometric data due to the incorporation of graph structure into the learning of node representations, which renders their comprehension challenging. In this paper, we first propose a unified framework satisfied by most existing GNN explainers. Then, we introduce GraphSVX, a post hoc local model-agnostic explanation method specifically designed for GNNs. GraphSVX is a decomposition technique that captures the “fair” contribution of each feature and node towards the explained prediction by constructing a surrogate model on a perturbed dataset. It extends to graphs and ultimately provides as explanation the Shapley Values from game theory. Experiments on real-world and synthetic datasets demonstrate that GraphSVX achieves state-of-the-art performance compared to baseline models while presenting core theoretical and human-centric properties.

Framework Image

Set up

If needed, install the required packages contained in requirements.txt as well as three additional packages that need to be installed separately (because of their dependency to pytorch).

pip install -r requirements.txt
pip install torch-sparse torch-scatter torch-cluster

To explain a model using GraphSVX

To explain the predictions of a model on a node or graph classification task, run

python3 --dataset='DATASET_NAME' --model='MODEL_NAME' --info=True

where 'DATASET_NAME' is the dataset name (e.g Cora, PubMed, syn1, syn2, syn4, syn5, syn6 or Mutagenicity) and 'MODEL_NAME' refers to the model used (e.g GAT or GCN). Note that all synthetic datasets exist and Cora/PubMed are downloaded directly. Only Mutagenicity requires you to go download it on the Internet on your own.

Hyperparameters for training are specificied in the Appendix of the paper and are described in the file. There are several parameters that you might want to specify:

  • the indexes of the nodes you would like to explain
  • the number of samples used in GraphSVX
  • some settings of GraphSVX such as feat, coal, g, regu, S, hv, fullempty, hops (see configs file)

To train a model

If you would like to train your own model on a chosen dataset, run

python3 --dataset='DATASET_NAME' --model='MODEL_NAME' --save=True

Otherwise, all trained models (except for Mutagenicity) already exist and can be used directly.


To follow the evaluation setting described in the paper, you should create a results folder and run the files:

  • evaluate GraphSVX on synthetic datasets with a ground truth. For instance, run this command to evaluate GraphSVX on the BA-Shapes dataset ('syn1').
python3 --dataset='syn1' --num_samples=400 --S=1 --coal='SmarterSeparate' --feat='Expectation'
python3 --dataset='syn2' --num_samples=800 --S=1 --coal='SmarterSeparate' --feat='All'
python3 --dataset='syn4' --num_samples=1400 --S=4 --coal='SmarterSeparate' --feat='Expectation' 
python3 --dataset='syn5' --num_samples=1000 --S=4 --coal='SmarterSeparate' --feat=‘Expectation’
python3 --dataset='syn6' --num_samples=200 --S=4 --coal='SmarterSeparate' --feat='Expectation'
python3 --dataset=Cora --num_samples=800 --hops=2 --hv='compute_pred' --test_samples=40 --model='GAT' --coal='NewSmarterSeparate' --S=3 --regu=0
  • evaluate GraphSVX on noisy dataset and observe number of noisy features included in explanations.
python3 --dataset=Cora --model=GAT --num_samples=3000 --test_samples=40 --hops=2 --hv=compute_pred_subgraph

All parameters are in the file, along with a small documentation.

The structure of the code is as follows:

In src:

  • defines GraphSVX and main baselines
  • import and process the data
  • define GNN models
  • train GNN models
  • stores useful variables
  • one of the evaluation of the paper, with real world datasets
  • explain all classes predictions
  • code for nice renderings
  • generates synthetic datasets


  • results: stores visualisation and evaluation results
  • data: contains some datasets, others will be downloaded automatically when launching the training script (Cora, PubMed)
  • models: contains our trained models
  • utils: some useful functions to construct datasets, store them, create plots, train models etc.


Please cite the original paper if you are using GraphSVX in your work.

  title={GraphSVX: Shapley Value Explanations for Graph Neural Networks},
  author={Duval, Alexandre and Malliaros, Fragkiskos},
  booktitle={European Conference on Machine Learning and Knowledge Discovery in Databases (ECML PKDD)},


Explanation method for Graph Neural Networks (GNNs)







No releases published


No packages published