<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from sklearn . datasets import make_blobs <EOL> from sklearn . cluster import KMeans <EOL> from sklearn . metrics import silhouette_samples , silhouette_score <EOL> import matplotlib . pyplot as plt <EOL> import matplotlib . cm as cm <EOL> import numpy as np <EOL> print ( __doc__ ) <EOL> X , y = make_blobs ( n_samples = <NUM_LIT> , <EOL> n_features = <NUM_LIT:2> , <EOL> centers = <NUM_LIT:4> , <EOL> cluster_std = <NUM_LIT:1> , <EOL> center_box = ( - <NUM_LIT> , <NUM_LIT> ) , <EOL> shuffle = True , <EOL> random_state = <NUM_LIT:1> ) <EOL> range_n_clusters = [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] <EOL> for n_clusters in range_n_clusters : <EOL> fig , ( ax1 , ax2 ) = plt . subplots ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> fig . set_size_inches ( <NUM_LIT> , <NUM_LIT:7> ) <EOL> ax1 . set_xlim ( [ - <NUM_LIT:0.1> , <NUM_LIT:1> ] ) <EOL> ax1 . set_ylim ( [ <NUM_LIT:0> , len ( X ) + ( n_clusters + <NUM_LIT:1> ) * <NUM_LIT:10> ] ) <EOL> clusterer = KMeans ( n_clusters = n_clusters , random_state = <NUM_LIT:10> ) <EOL> cluster_labels = clusterer . fit_predict ( X ) <EOL> silhouette_avg = silhouette_score ( X , cluster_labels ) <EOL> print ( "<STR_LIT>" , n_clusters , <EOL> "<STR_LIT>" , silhouette_avg ) <EOL> sample_silhouette_values = silhouette_samples ( X , cluster_labels ) <EOL> y_lower = <NUM_LIT:10> <EOL> for i in range ( n_clusters ) : <EOL> ith_cluster_silhouette_values = sample_silhouette_values [ cluster_labels == i ] <EOL> ith_cluster_silhouette_values . sort ( ) <EOL> size_cluster_i = ith_cluster_silhouette_values . shape [ <NUM_LIT:0> ] <EOL> y_upper = y_lower + size_cluster_i <EOL> color = cm . spectral ( float ( i ) / n_clusters ) <EOL> ax1 . fill_betweenx ( np . arange ( y_lower , y_upper ) , <EOL> <NUM_LIT:0> , ith_cluster_silhouette_values , <EOL> facecolor = color , edgecolor = color , alpha = <NUM_LIT> ) <EOL> ax1 . text ( - <NUM_LIT> , y_lower + <NUM_LIT:0.5> * size_cluster_i , str ( i ) ) <EOL> y_lower = y_upper + <NUM_LIT:10> <EOL> ax1 . set_title ( "<STR_LIT>" ) <EOL> ax1 . set_xlabel ( "<STR_LIT>" ) <EOL> ax1 . set_ylabel ( "<STR_LIT>" ) <EOL> ax1 . axvline ( x = silhouette_avg , color = "<STR_LIT>" , linestyle = "<STR_LIT>" ) <EOL> ax1 . set_yticks ( [ ] ) <EOL> ax1 . set_xticks ( [ - <NUM_LIT:0.1> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1> ] ) <EOL> colors = cm . spectral ( cluster_labels . astype ( float ) / n_clusters ) <EOL> ax2 . scatter ( X [ : , <NUM_LIT:0> ] , X [ : , <NUM_LIT:1> ] , marker = '<STR_LIT:.>' , s = <NUM_LIT:30> , lw = <NUM_LIT:0> , alpha = <NUM_LIT> , <EOL> c = colors ) <EOL> centers = clusterer . cluster_centers_ <EOL> ax2 . scatter ( centers [ : , <NUM_LIT:0> ] , centers [ : , <NUM_LIT:1> ] , <EOL> marker = '<STR_LIT:o>' , c = "<STR_LIT>" , alpha = <NUM_LIT:1> , s = <NUM_LIT:200> ) <EOL> for i , c in enumerate ( centers ) : <EOL> ax2 . scatter ( c [ <NUM_LIT:0> ] , c [ <NUM_LIT:1> ] , marker = '<STR_LIT>' % i , alpha = <NUM_LIT:1> , s = <NUM_LIT:50> ) <EOL> ax2 . set_title ( "<STR_LIT>" ) <EOL> ax2 . set_xlabel ( "<STR_LIT>" ) <EOL> ax2 . set_ylabel ( "<STR_LIT>" ) <EOL> plt . suptitle ( ( "<STR_LIT>" <EOL> "<STR_LIT>" % n_clusters ) , <EOL> fontsize = <NUM_LIT> , fontweight = '<STR_LIT>' ) <EOL> plt . show ( ) </s>
