<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> try : <EOL> from sklearn import cluster , datasets <EOL> from sklearn . preprocessing import StandardScaler <EOL> except ImportError : <EOL> raise ImportError ( '<STR_LIT>' ) <EOL> from bokeh . plotting import Figure , show , output_file , vplot , hplot <EOL> N = <NUM_LIT> <EOL> PLOT_SIZE = <NUM_LIT> <EOL> np . random . seed ( <NUM_LIT:0> ) <EOL> noisy_circles = datasets . make_circles ( n_samples = N , factor = <NUM_LIT> , noise = <NUM_LIT> ) <EOL> noisy_moons = datasets . make_moons ( n_samples = N , noise = <NUM_LIT> ) <EOL> centers = [ ( - <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( - <NUM_LIT:2> , - <NUM_LIT:3> ) , ( <NUM_LIT:2> , - <NUM_LIT:3> ) ] <EOL> blobs1 = datasets . make_blobs ( centers = centers , n_samples = N , cluster_std = <NUM_LIT> , random_state = <NUM_LIT:8> ) <EOL> blobs2 = datasets . make_blobs ( centers = centers , n_samples = N , cluster_std = <NUM_LIT> , random_state = <NUM_LIT:8> ) <EOL> colors = np . array ( [ x for x in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> colors = np . hstack ( [ colors ] * <NUM_LIT:20> ) <EOL> dbscan = cluster . DBSCAN ( eps = <NUM_LIT> ) <EOL> birch = cluster . Birch ( n_clusters = <NUM_LIT:2> ) <EOL> means = cluster . MiniBatchKMeans ( n_clusters = <NUM_LIT:2> ) <EOL> spectral = cluster . SpectralClustering ( n_clusters = <NUM_LIT:2> , eigen_solver = '<STR_LIT>' , affinity = "<STR_LIT>" ) <EOL> affinity = cluster . AffinityPropagation ( damping = <NUM_LIT> , preference = - <NUM_LIT:200> ) <EOL> algorithm = dbscan <EOL> plots = [ ] <EOL> for dataset in ( noisy_circles , noisy_moons , blobs1 , blobs2 ) : <EOL> X , y = dataset <EOL> X = StandardScaler ( ) . fit_transform ( X ) <EOL> algorithm . fit ( X ) <EOL> if hasattr ( algorithm , '<STR_LIT>' ) : <EOL> y_pred = algorithm . labels_ . astype ( np . int ) <EOL> else : <EOL> y_pred = algorithm . predict ( X ) <EOL> p = Figure ( webgl = True , title = algorithm . __class__ . __name__ , <EOL> plot_width = PLOT_SIZE , plot_height = PLOT_SIZE ) <EOL> p . scatter ( X [ : , <NUM_LIT:0> ] , X [ : , <NUM_LIT:1> ] , color = colors [ y_pred ] . tolist ( ) , alpha = <NUM_LIT:0.1> , ) <EOL> plots . append ( p ) <EOL> layout = vplot ( hplot ( * plots [ : <NUM_LIT:2> ] ) , hplot ( * plots [ <NUM_LIT:2> : ] ) ) <EOL> output_file ( "<STR_LIT>" , title = "<STR_LIT>" ) <EOL> show ( layout ) </s>
