Skip to content

Instantly share code, notes, and snippets.

@Ima8
Forked from bujol12/recursive_dbscan.md
Created November 20, 2019 05:38
Show Gist options
  • Select an option

  • Save Ima8/cc234d3437a3ebae8d50b16272be7de1 to your computer and use it in GitHub Desktop.

Select an option

Save Ima8/cc234d3437a3ebae8d50b16272be7de1 to your computer and use it in GitHub Desktop.
def recursive_dbscan(orders, min_radius, max_radius):
	while min_radius < max_radius:
		curr_radius = (min_radius+max_radius)/2
		
		clusters = DBSCAN(orders, curr_radius)
		
		if no_clusters < min_no_clusters: # not enough clusters
			max_radius = curr_radius-1
			else:
				min_radius = curr_radius+1
		
		if av_cluster_size > max_av_cluster_size: # choose the biggest cluster possible
			best_res = clusters
			max_av_cluster_size = av_cluster_size
	for cluster in best_res:
		if len(cluster) > max_len_cluster:
			best_res.remove(cluster)
			best_res.append(recursive_dbscan(cluster, radius_cluster))
		
	return best_res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment