3D Cat DataΒΆ
This example generates a Mapper built from a point-cloud sampled from a 3D model of a cat.
Visualization of the cat mapper
[1]:
import numpy as np
import sklearn
import kmapper as km
from pathlib import Path
import matplotlib.pyplot as plt
if Path("data/cat-reference.csv").exists():
cat_path = "data/cat-reference.csv"
elif Path("cat-reference.csv").exists():
cat_path = "cat-reference.csv"
else:
raise FileNotFoundError
data = np.genfromtxt(cat_path, delimiter=",")
mapper = km.KeplerMapper(verbose=2)
lens = mapper.fit_transform(data)
graph = mapper.map(
lens,
data,
clusterer=sklearn.cluster.DBSCAN(eps=0.1, min_samples=5),
cover=km.Cover(n_cubes=15, perc_overlap=0.2),
)
if Path("output/").is_dir():
prepend = "output/"
else:
prepend = "./"
mapper.visualize(graph, path_html=prepend + "cat.html")
km.draw_matplotlib(graph)
plt.show()
KeplerMapper(verbose=2)
..Composing projection pipeline of length 1:
Projections: sum
Distance matrices: False
Scalers: MinMaxScaler()
..Projecting on data shaped (7207, 3)
..Projecting data using: sum
..Scaling with: MinMaxScaler()
Mapping on data shaped (7207, 3) using lens shaped (7207, 1)
Minimal points in hypercube before clustering: 5
Creating 15 hypercubes.
> Found 2 clusters in hypercube 0.
> Found 2 clusters in hypercube 1.
> Found 2 clusters in hypercube 2.
> Found 1 clusters in hypercube 3.
> Found 2 clusters in hypercube 4.
> Found 2 clusters in hypercube 5.
> Found 1 clusters in hypercube 6.
> Found 1 clusters in hypercube 7.
> Found 1 clusters in hypercube 8.
> Found 1 clusters in hypercube 9.
> Found 1 clusters in hypercube 10.
> Found 1 clusters in hypercube 11.
> Found 1 clusters in hypercube 12.
> Found 1 clusters in hypercube 13.
> Found 1 clusters in hypercube 14.
Created 19 edges and 20 nodes in 0:00:00.074805.
Wrote visualization to: ./cat.html
no display found. Using non-interactive Agg backend
scikit-tda/kepler-mapper