#NEWLINE# def compute_bench( samples_range , features_range ) : #NEWLINE# #INDENT# it = 0 #NEWLINE# results = defaultdict ( ( lambda : [ ] ) ) #NEWLINE# chunk = 100 #NEWLINE# max_it = ( len ( samples_range ) * len ( features_range ) ) #NEWLINE# for n_samples in samples_range : #NEWLINE# #INDENT# for n_features in features_range : #NEWLINE# #INDENT# it += 1 #NEWLINE# print ( '==============================' ) #NEWLINE# print ( ( 'Iteration %03d of %03d' % ( it , max_it ) ) ) #NEWLINE# print ( '==============================' ) #NEWLINE# print ( ) #NEWLINE# data = nr . randint ( ( - 50 ) , 51 , ( n_samples , n_features ) ) #NEWLINE# print ( 'K-Means' ) #NEWLINE# tstart = time ( ) #NEWLINE# kmeans = KMeans ( init = 'k-means++' , n_clusters = 10 ) . fit ( data ) #NEWLINE# delta = ( time ( ) - tstart ) #NEWLINE# print ( ( 'Speed: %0.3fs' % delta ) ) #NEWLINE# print ( ( 'Inertia: %0.5f' % kmeans . inertia_ ) ) #NEWLINE# print ( ) #NEWLINE# results [ 'kmeans_speed' ] . append ( delta ) #NEWLINE# results [ 'kmeans_quality' ] . append ( kmeans . inertia_ ) #NEWLINE# print ( 'Fast K-Means' ) #NEWLINE# mbkmeans = MiniBatchKMeans ( init = 'k-means++' , n_clusters = 10 , batch_size = chunk ) #NEWLINE# tstart = time ( ) #NEWLINE# mbkmeans . fit ( data ) #NEWLINE# delta = ( time ( ) - tstart ) #NEWLINE# print ( ( 'Speed: %0.3fs' % delta ) ) #NEWLINE# print ( ( 'Inertia: %f' % mbkmeans . inertia_ ) ) #NEWLINE# print ( ) #NEWLINE# print ( ) #NEWLINE# results [ 'MiniBatchKMeans Speed' ] . append ( delta ) #NEWLINE# results [ 'MiniBatchKMeans Quality' ] . append ( samples_range . inertia_ ) #NEWLINE# #UNINDENT# #UNINDENT# return results