MeanShift to find maxima

data = np.array([[1, 4, 3], [2, .6, 1.2], [2, 1, 1.2], [2, 0.5, 1.4], [5, .5, 0], [0, 0, 0], [1, 4, 3], [5, .5, 0], [2, .5, 1.2]]) values = data.T kde = stats.gaussian_kde(values) density = kde(values) x,y,z = values ## ##clustering ## xx = range(len(density)) m = np.array([xx, density]).T ms = MeanShift() ms.fit(m) labels = ms.labels_ cluster_centers = ms.cluster_centers_ labels_unique = np.unique(labels) n_clusters = len(labels_unique) print(density) print(labels) print("number of estimated cluster", n_clusters) ############################### ### output ### [ 0.03372205 0.0564562 0.04343546 0.04631113 0.033694 0.01660216 0.03372205 0.033694 0.05600625] [5 2 2 0 0 4 1 1 3] number of estimated cluster 6 ###############################

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.