<s> import numpy as np <EOL> from sklearn . cluster import MeanShift , estimate_bandwidth <EOL> from sklearn . datasets . samples_generator import make_blobs <EOL> centers = [ [ <NUM_LIT:1> , <NUM_LIT:1> ] , [ - <NUM_LIT:1> , - <NUM_LIT:1> ] , [ <NUM_LIT:1> , - <NUM_LIT:1> ] ] <EOL> X , _ = make_blobs ( n_samples = <NUM_LIT> , centers = centers , cluster_std = <NUM_LIT> ) <EOL> bandwidth = estimate_bandwidth ( X , quantile = <NUM_LIT> , n_samples = <NUM_LIT> ) <EOL> ms = MeanShift ( bandwidth = bandwidth , bin_seeding = True ) <EOL> ms . fit ( X ) <EOL> labels = ms . labels_ <EOL> cluster_centers = ms . cluster_centers_ <EOL> labels_unique = np . unique ( labels ) <EOL> n_clusters_ = len ( labels_unique ) <EOL> print ( "<STR_LIT>" % n_clusters_ ) <EOL> import pylab as pl <EOL> from itertools import cycle <EOL> pl . figure ( <NUM_LIT:1> ) <EOL> pl . clf ( ) <EOL> colors = cycle ( '<STR_LIT>' ) <EOL> for k , col in zip ( range ( n_clusters_ ) , colors ) : <EOL> my_members = labels == k <EOL> cluster_center = cluster_centers [ k ] <EOL> pl . plot ( X [ my_members , <NUM_LIT:0> ] , X [ my_members , <NUM_LIT:1> ] , col + '<STR_LIT:.>' ) <EOL> pl . plot ( cluster_center [ <NUM_LIT:0> ] , cluster_center [ <NUM_LIT:1> ] , '<STR_LIT:o>' , markerfacecolor = col , <EOL> markeredgecolor = '<STR_LIT:k>' , markersize = <NUM_LIT> ) <EOL> pl . title ( '<STR_LIT>' % n_clusters_ ) <EOL> pl . show ( ) </s>
