Scikit-network: Graph Analysis in Python

Thomas Bonald, Nathan de Lara, Quentin Lutz, Bertrand Charpentier

Abstract

Scikit-network is a high-performance Python library designed for the analysis of massive graphs using an API that mirrors the familiar scikit-learn workflow. By leveraging sparse matrix representations and Cython-optimized code, it achieves the speed of C++ based libraries while maintaining a minimal memory footprint and extreme ease of use.

The Challenge of Large-Scale Graph Analysis

In the world of data science, graphs are everywhere—from social networks to recommendation engines. However, analyzing these structures at scale is notoriously difficult. Standard machine learning libraries like scikit-learn are built for dense data and struggle with the sparse nature of graphs containing millions of nodes.

Conversely, existing graph libraries often force a trade-off: NetworkX is user-friendly but too slow for large datasets, while high-performance tools like iGraph or graph-tool can have complex APIs or heavy installation dependencies. The authors of scikit-network aim to fill this gap by providing a "Python-native" feel with "C++-level" performance, specifically optimized for the sparse Compressed Sparse Row (CSR) format.

Methodology and Design Philosophy

The core philosophy of scikit-network is efficiency through simplicity. Key technical choices include:

  • Sparse Matrix Representation: Instead of treating graphs as complex objects, the library treats them as adjacency matrices in SciPy’s CSR format. This allows the library to use highly optimized linear algebra routines.
  • Hybrid Implementation: Performance is achieved through a combination of fast matrix-vector products (via SciPy), compiled code (via Cython), and parallel processing.
  • The Scikit-learn API: The library adopts the fit(), transform(), and predict() paradigm. This makes it immediately intuitive for anyone who has used scikit-learn for standard machine learning.
  • Bipartite Support: Unlike many tools that require bipartite graphs to be converted into unipartite ones, scikit-network can operate directly on biadjacency matrices, which is a significant advantage for applications like user-item recommendation.

Performance Evaluation

To demonstrate the library's capabilities, the authors evaluated it using the Orkut graph, a substantial dataset featuring over 3 million nodes and 117 million edges. The benchmarks against NetworkX, iGraph, and graph-tool yielded impressive results in both speed and memory efficiency.

Execution Speed

Scikit-network demonstrates competitive or superior execution times across various algorithms. For Louvain clustering, it completed the task in 771 seconds, significantly faster than iGraph’s 1,978 seconds. In PageRank tasks, it matched the speed of graph-tool and outperformed iGraph.

Execution time comparison (in seconds) for common graph algorithms across different libraries.

Memory Footprint

Memory efficiency is often the primary bottleneck in graph analysis. Scikit-network used only 1,222 MB of RAM to load the Orkut graph. In comparison, iGraph required 17,765 MB, and graph-tool required 10,366 MB. NetworkX suffered a memory overflow and could not load the graph at all.

RAM usage comparison (in MB) for loading the Orkut dataset across different libraries.

Conclusion and Future Work

Scikit-network represents a major step forward for Python users who need to perform heavy-duty graph analytics without leaving the comfort of the scikit-learn ecosystem. While the current implementation focuses on static graphs and single-machine performance, its minimal dependencies and high efficiency make it a robust tool for modern data science. Future work may explore dynamic graph handling and distributed processing for graphs that exceed the RAM of a single workstation.

Summary updated

BibTeX
@article{bonald2020scikit,
  author = {Thomas Bonald and Nathan de Lara and Quentin Lutz and Bertrand Charpentier},
  title = {{Scikit-network: Graph Analysis in Python}},
  journal = {J. Mach. Learn. Res.},
  year = {2020},
  url = {https://openreview.net/forum?id=s7rvGIMnP8},
}
Figure