<s> """<STR_LIT>""" <EOL> from io import BytesIO <EOL> from os . path import exists <EOL> from os import makedirs <EOL> try : <EOL> import urllib2 <EOL> urlopen = urllib2 . urlopen <EOL> except ImportError : <EOL> import urllib . request <EOL> urlopen = urllib . request . urlopen <EOL> import numpy as np <EOL> from scipy . io . matlab import loadmat <EOL> from . base import get_data_home , Bunch <EOL> from . base import _pkl_filepath <EOL> from . . utils import check_random_state <EOL> from . . externals import joblib <EOL> DATA_URL = "<STR_LIT>" <EOL> TARGET_FILENAME = "<STR_LIT>" <EOL> MODULE_DOCS = __doc__ <EOL> def fetch_olivetti_faces ( data_home = None , shuffle = False , random_state = <NUM_LIT:0> , <EOL> download_if_missing = True ) : <EOL> """<STR_LIT>""" <EOL> data_home = get_data_home ( data_home = data_home ) <EOL> if not exists ( data_home ) : <EOL> makedirs ( data_home ) <EOL> filepath = _pkl_filepath ( data_home , TARGET_FILENAME ) <EOL> if not exists ( filepath ) : <EOL> print ( '<STR_LIT>' <EOL> % ( DATA_URL , data_home ) ) <EOL> fhandle = urlopen ( DATA_URL ) <EOL> buf = BytesIO ( fhandle . read ( ) ) <EOL> mfile = loadmat ( buf ) <EOL> faces = mfile [ '<STR_LIT>' ] . T . copy ( ) <EOL> joblib . dump ( faces , filepath , compress = <NUM_LIT:6> ) <EOL> del mfile <EOL> else : <EOL> faces = joblib . load ( filepath ) <EOL> faces = np . float32 ( faces ) <EOL> faces = faces - faces . min ( ) <EOL> faces /= faces . max ( ) <EOL> faces = faces . reshape ( ( <NUM_LIT> , <NUM_LIT:64> , <NUM_LIT:64> ) ) . transpose ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> target = np . array ( [ i // <NUM_LIT:10> for i in range ( <NUM_LIT> ) ] ) <EOL> if shuffle : <EOL> random_state = check_random_state ( random_state ) <EOL> order = random_state . permutation ( len ( faces ) ) <EOL> faces = faces [ order ] <EOL> target = target [ order ] <EOL> return Bunch ( data = faces . reshape ( len ( faces ) , - <NUM_LIT:1> ) , <EOL> images = faces , <EOL> target = target , <EOL> DESCR = MODULE_DOCS ) </s>
