{"id":19296577,"url":"https://github.com/alexduvalinho/graphsvx","last_synced_at":"2026-04-02T02:06:50.513Z","repository":{"id":140139997,"uuid":"357632803","full_name":"AlexDuvalinho/GraphSVX","owner":"AlexDuvalinho","description":"Explanation method for Graph Neural Networks (GNNs)","archived":false,"fork":false,"pushed_at":"2025-04-27T12:32:29.000Z","size":1449,"stargazers_count":71,"open_issues_count":4,"forks_count":18,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-04T09:03:27.783Z","etag":null,"topics":["explainable-ai","explainer","gnn","graphs"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexDuvalinho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-13T17:15:46.000Z","updated_at":"2025-08-13T07:19:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"b2e6bb1d-89fc-414c-9a8a-50bb0eebd3d0","html_url":"https://github.com/AlexDuvalinho/GraphSVX","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AlexDuvalinho/GraphSVX","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexDuvalinho%2FGraphSVX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexDuvalinho%2FGraphSVX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexDuvalinho%2FGraphSVX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexDuvalinho%2FGraphSVX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexDuvalinho","download_url":"https://codeload.github.com/AlexDuvalinho/GraphSVX/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexDuvalinho%2FGraphSVX/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31294398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T01:43:37.129Z","status":"online","status_checked_at":"2026-04-02T02:00:08.535Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["explainable-ai","explainer","gnn","graphs"],"created_at":"2024-11-09T22:48:14.076Z","updated_at":"2026-04-02T02:06:50.483Z","avatar_url":"https://github.com/AlexDuvalinho.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# GraphSVX: Shapley Value Explanations for Graph Neural Networks \n\nThis repository contains the source code for the paper [GraphSVX: Shapley Value Explanations for Graph Neural Networks_](https://2021.ecmlpkdd.org/wp-content/uploads/2021/07/sub_135.pdf), \nby 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_. \n\n### Abstract\nGraph 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.\n\n![Framework Image](/utils/pipeline_figure.png)\n\n### Set up \nIf needed, install the required packages contained in [requirements.txt](/requirements.txt) as well as three additional packages \nthat need to be installed separately (because of their dependency to pytorch). \n```\npip install -r requirements.txt\npip install torch-sparse torch-scatter torch-cluster\n```\n\n### To explain a model using GraphSVX\nTo explain the predictions of a model on a node or graph classification task, run [script_explain.py](/script_explain.py):\n```\npython3 script_explain.py --dataset='DATASET_NAME' --model='MODEL_NAME' --info=True\n```\nwhere '_DATASET_NAME_' is the dataset name (e.g Cora, PubMed, syn1, syn2, syn4, syn5, syn6 or Mutagenicity) and \n'_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\nrequires you to go download it on the Internet on your own. \n\nHyperparameters for training are specificied in the Appendix of the paper\nand are described in the configs.py file. There are several parameters that you might want to specify: \n- the indexes of the nodes you would like to explain\n- the number of samples used in GraphSVX\n- some settings of GraphSVX such as feat, coal, g, regu, S, hv, fullempty, hops (see configs file)\n\n### To train a model \nIf you would like to train your own model on a chosen dataset, run [script_train.py](/script_train.py): \n```\npython3 script_train.py --dataset='DATASET_NAME' --model='MODEL_NAME' --save=True\n```\nOtherwise, all trained models (except for Mutagenicity) already exist and can be used directly. \n\n### Evaluation \nTo follow the evaluation setting described in the paper, you should create a results folder and run the files: \n- [script_eval_gt.py](/script_eval_gt.py): evaluate GraphSVX on synthetic datasets with a ground truth. For instance, run this command to evaluate GraphSVX on the BA-Shapes dataset ('syn1'). \n```\npython3 script_eval_gt.py --dataset='syn1' --num_samples=400 --S=1 --coal='SmarterSeparate' --feat='Expectation'\npython3 script_eval_gt.py --dataset='syn2' --num_samples=800 --S=1 --coal='SmarterSeparate' --feat='All'\npython3 script_eval_gt.py --dataset='syn4' --num_samples=1400 --S=4 --coal='SmarterSeparate' --feat='Expectation' \npython3 script_eval_gt.py --dataset='syn5' --num_samples=1000 --S=4 --coal='SmarterSeparate' --feat=‘Expectation’\npython3 script_eval_gt.py --dataset='syn6' --num_samples=200 --S=4 --coal='SmarterSeparate' --feat='Expectation'\n```\n- [script_eval_noise_node.py](/script_eval_noise_node.py): evaluate GraphSVX on noisy dataset and observe number of noisy nodes included in explanations.\n```\npython3 script_eval_noise_node.py --dataset=Cora --num_samples=800 --hops=2 --hv='compute_pred' --test_samples=40 --model='GAT' --coal='NewSmarterSeparate' --S=3 --regu=0\n```\n- [script_eval_noise_feat.py](/script_eval_noise_feat.py): evaluate GraphSVX on noisy dataset and observe number of noisy features included in explanations.\n```\npython3 script_eval_noise_feat.py --dataset=Cora --model=GAT --num_samples=3000 --test_samples=40 --hops=2 --hv=compute_pred_subgraph\n```\nAll parameters are in the configs.py file, along with a small documentation. \n\n\n### The structure of the code is as follows: \nIn src: \n- explainers.py: defines GraphSVX and main baselines\n- data.py: import and process the data \n- models.py: define GNN models\n- train.py: train GNN models\n- utils.py: stores useful variables\n- eval.py: one of the evaluation of the paper, with real world datasets\n- eval_multiclass.py: explain all classes predictions\n- plots.py: code for nice renderings\n- gengraph.py: generates synthetic datasets\n\nOutside: \n- results: stores visualisation and evaluation results\n- data: contains some datasets, others will be downloaded automatically when launching the training script (Cora, PubMed)\n- models: contains our trained models\n- utils: some useful functions to construct datasets, store them, create plots, train models etc. \n\n### Citation \nPlease cite the original paper if you are using GraphSVX in your work. \n```\n@inproceedings{duval2021graphsvx,\n  title={GraphSVX: Shapley Value Explanations for Graph Neural Networks},\n  author={Duval, Alexandre and Malliaros, Fragkiskos},\n  booktitle={European Conference on Machine Learning and Knowledge Discovery in Databases (ECML PKDD)},\n  year={2021}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexduvalinho%2Fgraphsvx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexduvalinho%2Fgraphsvx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexduvalinho%2Fgraphsvx/lists"}