In [1]:
%load_ext autoreload
%autoreload 2
In [2]:
import numpy as np
import sklearn
from sklearn import datasets
try:
import umap
except ImportError:
print("This example requires the UMAP library. You can install it with the command `!pip install umap-learn`")
import warnings
warnings.filterwarnings("ignore")
In [3]:
import kmapper as km
from kmapper.plotlyviz import plotlyviz
from kmapper.plotlyviz import *
import plotly.graph_objs as go
import ipywidgets as ipw
In [4]:
data, labels = datasets.load_digits().data, datasets.load_digits().target
In [ ]:
mapper = km.KeplerMapper(verbose=0)
projected_data = mapper.fit_transform(data, projection=umap.UMAP(n_neighbors=8,
min_dist=0.65,
n_components=2,
metric='euclidean',
random_state=3571))
# Get the simplicial complex
scomplex = mapper.map(projected_data,
clusterer=sklearn.cluster.DBSCAN(eps=0.3, min_samples=15),
coverer=km.Cover(35, 0.9))
The mapper graph nodes associated to this data set are colored according to the color_function
values with Viridis colorscale,
which is the default color scale, defined in plotlyviz
.
In [ ]:
color_function = projected_data[:, 1]-projected_data[:, 1].min()
plotlyviz(scomplex,
title='Mapper graph of digits dataset',
color_function=color_function,
color_function_name='Distance to y-min',
node_linecolor='rgb(100,100,100)',
bgcolor='rgb(240,240,240)',
width=620, height=620,
summary_height=350,
summary_left=10,
hist_left=25,
hist_right=10,
graph_data=True)
In [ ]:
color_function = projected_data[:, 1]-projected_data[:, 1].min()
plotlyviz(scomplex,
title='Mapper graph of digits dataset',
color_function=color_function,
color_function_name='Distance to y-min',
node_linecolor='rgb(100,100,100)',
bgcolor='rgb(240,240,240)',
width=620, height=620,
summary_height=350,
summary_left=10,
hist_left=25,
hist_right=10,
member_textbox_width=500,
dashboard=True)
In [ ]: