Adapters example

Demonstration using the networkx adapter. This example requires installing the networkx library before continuing:

pip install networkx
In [1]:
import kmapper
from sklearn import datasets
import networkx as nx

Construct data and a simple Mapper

In [2]:
data = datasets.make_circles(n_samples=1000)[0]
In [3]:
km = kmapper.KeplerMapper()
lens = km.project(data)
graph =, lens=lens)

Convert Mapper to a networkx graph

We can easily convert the graph to a networkx graph representation. This enables us to use many of the commonly provided algorithms and visualization methods.

In [4]:
nx_graph = kmapper.adapter.to_nx(graph)
In [6]:
In [ ]: