def do_analysis(data, lens, name_prefix, nc, po, metric='euclidean'): graph = mapper.map(lens, data.values, clusterer=lk.LinkageGap(verbose=0, metric=metric), cover=km.Cover(n_cubes=nc, perc_overlap=po)) name = "{}_n{}_o{}".format(name_prefix, nc, po) mapper.visualize( graph, # color_values=target.values, color_values=lens, color_function_name=name_prefix, path_html=name + "_nm_diabetes_RM.html", title=name + "nm_diabetes_RM") nx_graph_simple = expo.kmapper_to_nxmapper(graph) expo.cytoscapejson_dump(nx_graph_simple, name + "_nm_diabetes_RM_simple.cyjs") extra_data = {x: list(data.loc[:, x]) for x in data.columns} extra_transforms = { x: np.mean for x in extra_data if x != "Clinical_classification" } nx_graph = expo.kmapper_to_nxmapper(graph, node_extra_data=extra_data, node_transforms=extra_transforms) expo.cytoscapejson_dump(nx_graph, name + "_nm_diabetes_RM.cyjs")
def do_analysis(data, lens, name_prefix, nc, po): name = "{}_n{}_o{}".format(name_prefix, nc, po) graph = mapper.map(lens, data, clusterer=lk.LinkageGap(verbose=0), cover=km.Cover(n_cubes=nc, perc_overlap=po)) mapper.visualize(graph, color_function=lens, path_html=name + "_cat.html", title=name + "_cat")
def do_analysis(data, lens, cf, name_prefix, nc, po): name = "{:s}_n{:d}_o{:.2f}".format(name_prefix, nc, po) graph = mapper.map(lens, data, clusterer=lk.LinkageGap(verbose=0, metric='euclidean'), cover=km.Cover(n_cubes=nc, perc_overlap=po)) mapper.visualize(graph, color_function=cf, path_html=name + "_travel.html", title=name + "_travel")
def do_analysis(data, lens, name_prefix, nc, po,metric='euclidean'): graph = mapper.map(lens, data.values, clusterer = lk.LinkageGap(verbose=0,metric=metric), cover=km.Cover(n_cubes=nc, perc_overlap=po)) name = "{}_n{}_o{}".format(name_prefix,nc, po) mapper.visualize(graph, # color_function=target.values, color_function=lens, path_html=name + "_nm_diabetes_RM.html", title=name + "nm_diabetes_RM")
def do_analysis(lens, name_prefix, nc, po): graph = mapper.map( lens, data, clusterer=lk.LinkageGap(verbose=0), # clusterer=sklearn.cluster.DBSCAN(1, min_samples=0), cover=km.Cover(n_cubes=nc, perc_overlap=po)) name = "{}_n{}_o{}".format(name_prefix, nc, po) mapper.visualize(graph, color_function=target, path_html=name + "_iris.html", title=name + "_iris")
def do_analysis(data, dists, lens, name_prefix, nc, po): name = "{}_n{}_o{}".format(name_prefix, nc, po) graph = mapper.map(lens, dists, clusterer=lk.LinkageGap(verbose=0, metric="precomputed"), precomputed=True, cover=km.Cover(n_cubes=nc, perc_overlap=po)) mapper.visualize(graph, color_values=lens, color_function_name=name_prefix, path_html=name + "_cat.html", title=name + "_cat")
def do_analysis(data, lens, cf, name_prefix, nc, po): name = "{:s}_n{:d}_o{:.2f}".format(name_prefix, nc, po) graph = mapper.map(lens, data.values, clusterer=lk.LinkageGap(verbose=0, metric='euclidean'), cover=km.Cover(n_cubes=nc, perc_overlap=po)) mapper.visualize(graph, color_function=cf, path_html=name + "_travel.html", title=name + "_travel") extra_data = {x: list(data.loc[:, x]) for x in data.columns} extra_transforms = {x: np.mean for x in extra_data} nx_graph = expo.kmapper_to_nxmapper(graph, node_extra_data=extra_data, node_transforms=extra_transforms) expo.cytoscapejson_dump(nx_graph, name + "_travel.cyjs")
import kmapper as km import mapperutils.linkage_gap as lk import mapperutils.visualization as viz mapper = km.KeplerMapper(verbose=2) hand = trimesh.load_mesh("../0_data/hand/hand_simplified3k5.stl") data = np.array(hand.vertices) lens = data[:, 1:2] plot = True if plot: viz.scatter3d(data, lens, colorsMap='viridis', show=False) viz.plt.gca().view_init(elev=90, azim=0) viz.axisEqual3D(viz.plt.gca()) viz.plt.show() n = 7 p = 0.2 graph = mapper.map(lens, data, clusterer=lk.LinkageGap(verbose=0), cover=km.Cover(n_cubes=n, perc_overlap=p)) name = "n{}_p{}".format(n, p) mapper.visualize(graph, color_function=lens, path_html="hand_only_" + name + ".html", title="hand, " + name)
def test_heuristics_precomputed(): dists = spd.squareform(spd.pdist(X)) fg = lk.LinkageGap(heuristic='firstgap', metric='precomputed').fit(dists) assert len(np.unique(fg.labels_)) == 3
def test_heuristics(): fg = lk.LinkageGap(heuristic='firstgap').fit(X) assert len(np.unique(fg.labels_)) == 3 with pytest.raises(Exception): fg = lk.LinkageGap(heuristic='foobar')