def fit_transform(self, X, y=None, init=None): mapper = km.KeplerMapper() dist_matrix, lens, bp = mapper.fit_transform( X, projection=self.filter_function, BP=self.BP) graph = mapper.map(lens, X, clusterer=self.clusterer, nr_cubes=self.nr_cubes, overlap_perc=self.overlap_perc, auto_tuning=self.auto_tuning) landmarks = self._get_landmarks(graph) Landmark, links = self._compute_skeleton(landmarks, X) self.landmarks = Landmark self.skeleton = links self.basePoint = bp self.lens = lens X = X.tolist() Index_of_landmarks = [] for i in range(0, len(Landmark)): Index_of_landmarks.append((X.index(Landmark.tolist()[i]))) self.landmarks_indexes = Index_of_landmarks Y, proj_landmark = self.Landmark_Isomap(X, 2, Index_of_landmarks, dist_matrix) return Y
import StringIO from scipy.misc import imsave, toimage import base64 tooltip_s = [] for image_data in data: output = StringIO.StringIO() img = toimage(image_data.reshape((8,8))) # Data was a flat row of 64 "pixels". img.save(output, format="PNG") contents = output.getvalue() tooltip_s.append( """ <img src="data:image/png;base64,%s"> """%base64.b64encode(contents).replace("\n","") ) output.close() tooltip_s = km.np.array(tooltip_s) # need to make sure to feed it as a NumPy array, not a list # Initialize to use t-SNE with 2 components (reduces data to 2 dimensions). Also note high overlap_percentage. mapper = km.KeplerMapper(cluster_algorithm=km.cluster.DBSCAN(eps=0.3, min_samples=15), reducer = km.manifold.TSNE(), nr_cubes=35, overlap_perc=0.9, link_local=False, verbose=2) # Fit and transform data data = mapper.fit_transform(data) # Create the graph complex = mapper.map(data, dimension_index=[0,1], dimension_name="t-SNE(2) 2D") # Create the visualizations (increased the graph_gravity for a tighter graph-look.) # Tooltips with image data for every cluster member mapper.visualize(complex, "keplermapper_digits_custom_tooltips.html", "Digits", graph_gravity=0.25, custom_tooltips=tooltip_s) # Tooltips with the target y-labels for every cluster member mapper.visualize(complex, "keplermapper_digits_ylabel_tooltips.html", "Digits", graph_gravity=0.25, custom_tooltips=labels)
__copyright__ = "Copyright (C) 2017 Inria" __license__ = "GPL v3" parser = argparse.ArgumentParser(description='Creates an html Keppler Mapper ' 'file to visualize a SC.txt file.', epilog='Example: ' './KeplerMapperVisuFromTxtFile.py ' '-f ../../data/points/human.off_sc.txt' '- Constructs an human.off_sc.html file.') parser.add_argument("-f", "--file", type=str, required=True) args = parser.parse_args() with open(args.file, 'r') as f: network = {} mapper = km.KeplerMapper(verbose=0) data = np.zeros((3, 3)) projected_data = mapper.fit_transform(data, projection="sum", scaler=None) nodes = defaultdict(list) links = defaultdict(list) custom = defaultdict(list) dat = f.readline() lens = f.readline() color = f.readline() param = [float(i) for i in f.readline().split(" ")] nums = [int(i) for i in f.readline().split(" ")] num_nodes = nums[0] num_edges = nums[1]
import km data = km.np.genfromtxt('horse-reference.csv',delimiter=',') mapper = km.KeplerMapper(cluster_algorithm=km.cluster.DBSCAN(eps=0.3, min_samples=3), nr_cubes=25, link_local=False, overlap_perc=0.7, verbose=1) mapper.fit(data) complex = mapper.map(data, dimension_index=1, dimension_name="Y-axis") mapper.visualize(complex, "horse_keplermapper_output.html", "horse-reference.csv") # You may want to visualize the original point cloud data in 3D scatter too """ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(data[:,0],data[:,1],data[:,2]) plt.savefig("horse-reference.csv.png") plt.show() """
import km data = km.np.genfromtxt('cat-reference.csv',delimiter=',') mapper = km.KeplerMapper() lens = mapper.fit_transform(data) graph = mapper.map(lens, data, clusterer=km.cluster.DBSCAN(eps=0.1, min_samples=5), nr_cubes=15, overlap_perc=0.2) mapper.visualize(graph, path_html="cat_keplermapper_output.html") # You may want to visualize the original point cloud data in 3D scatter too """ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(data[:,0],data[:,1],data[:,2]) plt.savefig("cat-reference.csv.png") plt.show() """
import km data = km.np.genfromtxt('cat-reference.csv', delimiter=',') mapper = km.KeplerMapper(cluster_algorithm=km.cluster.DBSCAN(eps=0.1, min_samples=5), nr_cubes=10, overlap_perc=0.8, verbose=1) mapper.fit(data) complex = mapper.map(data, dimension_index=1, dimension_name="Y-axis") mapper.visualize(complex, "cat_keplermapper_output.html", "cat-reference.csv") # You may want to visualize the original point cloud data in 3D scatter too """ import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(data[:,0],data[:,1],data[:,2]) plt.savefig("cat-reference.csv.png") plt.show() """