<s> """<STR_LIT>""" <EOL> print ( __doc__ ) <EOL> import time <EOL> import matplotlib . pyplot as plt <EOL> import numpy as np <EOL> from sklearn import datasets <EOL> from sklearn . cluster import MiniBatchKMeans <EOL> from sklearn . feature_extraction . image import extract_patches_2d <EOL> faces = datasets . fetch_olivetti_faces ( ) <EOL> print ( '<STR_LIT>' ) <EOL> rng = np . random . RandomState ( <NUM_LIT:0> ) <EOL> kmeans = MiniBatchKMeans ( n_clusters = <NUM_LIT> , random_state = rng , verbose = True ) <EOL> patch_size = ( <NUM_LIT:20> , <NUM_LIT:20> ) <EOL> buffer = [ ] <EOL> index = <NUM_LIT:1> <EOL> t0 = time . time ( ) <EOL> index = <NUM_LIT:0> <EOL> for _ in range ( <NUM_LIT:6> ) : <EOL> for img in faces . images : <EOL> data = extract_patches_2d ( img , patch_size , max_patches = <NUM_LIT:50> , <EOL> random_state = rng ) <EOL> data = np . reshape ( data , ( len ( data ) , - <NUM_LIT:1> ) ) <EOL> buffer . append ( data ) <EOL> index += <NUM_LIT:1> <EOL> if index % <NUM_LIT:10> == <NUM_LIT:0> : <EOL> data = np . concatenate ( buffer , axis = <NUM_LIT:0> ) <EOL> data -= np . mean ( data , axis = <NUM_LIT:0> ) <EOL> data /= np . std ( data , axis = <NUM_LIT:0> ) <EOL> kmeans . partial_fit ( data ) <EOL> buffer = [ ] <EOL> if index % <NUM_LIT:100> == <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' <EOL> % ( index , <NUM_LIT:6> * len ( faces . images ) ) ) <EOL> dt = time . time ( ) - t0 <EOL> print ( '<STR_LIT>' % dt ) <EOL> plt . figure ( figsize = ( <NUM_LIT> , <NUM_LIT:4> ) ) <EOL> for i , patch in enumerate ( kmeans . cluster_centers_ ) : <EOL> plt . subplot ( <NUM_LIT:9> , <NUM_LIT:9> , i + <NUM_LIT:1> ) <EOL> plt . imshow ( patch . reshape ( patch_size ) , cmap = plt . cm . gray , <EOL> interpolation = '<STR_LIT>' ) <EOL> plt . xticks ( ( ) ) <EOL> plt . yticks ( ( ) ) <EOL> plt . suptitle ( '<STR_LIT>' % <EOL> ( dt , <NUM_LIT:8> * len ( faces . images ) ) , fontsize = <NUM_LIT:16> ) <EOL> plt . subplots_adjust ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> plt . show ( ) </s>
