-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
41 lines (34 loc) · 1.24 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
Copyright ⓒ 2021 성균관대학교 수학과 정재헌(JaeHeon Jeong) All Rights Reserved
email : [email protected]
"""
import numpy as np
from scipy.spatial.distance import pdist, squareform
from kepler_mapper import kmapper as km
import sklearn
from sklearn import datasets
custom_metric = np.load("law_data/custom_metric.npy")
# Initialize
mapper = km.KeplerMapper(verbose=1)
projected_data = mapper.project(
projection=sklearn.manifold.TSNE(),
distance_matrix="precomputed"
)
# Set hyperparameters for clustering
cubes=15
overlap=0.15
epsilon=0.6
# Create dictionary called 'graph' with nodes, edges and meta-information
graph = mapper.map(
projected_data,
X=custom_metric,
cover=km.Cover(n_cubes=cubes, perc_overlap=overlap),
precomputed=True,
clusterer=sklearn.cluster.DBSCAN(eps=epsilon, metric='precomputed').fit(custom_metric)
)
# Visualize it
mapper.visualize(
graph,
path_html="keplermapper_output_"+str(cubes)+"_"+str(overlap)+"_"+str(epsilon)+".html",
title="law analysis using tda ("+str(cubes)+"_"+str(overlap)+"_"+str(epsilon)+")",
custom_tooltips=np.load("law_data/law_list.npy"))