Using Kepler Mapper in Jupyter NotebookΒΆ
Last run 2021-10-08 with kmapper version 2.0.1
[1]:
import kmapper as km
from kmapper import jupyter # Creates custom CSS full-size Jupyter screen
[2]:
# Some sample data
from sklearn import datasets
data, labels = datasets.make_circles(n_samples=5000, noise=0.03, factor=0.3)
# Initialize
mapper = km.KeplerMapper(verbose=1)
# Fit to and transform the data
projected_data = mapper.fit_transform(data, projection=[0,1]) # X-Y axis
# Create a cover with 10 elements
cover = km.Cover(n_cubes=10)
# Create dictionary called 'graph' with nodes, edges and meta-information
graph = mapper.map(projected_data, data, cover=cover)
# Visualize it
_ = mapper.visualize(graph, path_html="output/make_circles_keplermapper_output.html",
title="make_circles(n_samples=5000, noise=0.03, factor=0.3)")
## Uncomment the below to view the above-generated visualization
#
# jupyter.display(path_html="output/make_circles_keplermapper_output.html")
## Alternatively, use an IFrame to display a vis with a set width and height
#
# from IPython.display import IFrame
# IFrame(src="http://mlwave.github.io/tda/word2vec-gender-bias.html", width=800, height=600)
KeplerMapper(verbose=1)
..Composing projection pipeline of length 1:
Projections: [0, 1]
Distance matrices: False
Scalers: MinMaxScaler()
..Projecting on data shaped (5000, 2)
..Projecting data using: [0, 1]
..Scaling with: MinMaxScaler()
Mapping on data shaped (5000, 2) using lens shaped (5000, 2)
Creating 100 hypercubes.
Created 242 edges and 92 nodes in 0:00:00.270250.
Wrote visualization to: output/make_circles_keplermapper_output.html