<s> import os <EOL> import numpy as np <EOL> def load_gender_data ( ntrain = <NUM_LIT> , ntest = <NUM_LIT> ) : <EOL> import pandas as pd <EOL> file_loc = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> relative_path = "<STR_LIT>" <EOL> fullpath = os . path . join ( file_loc , relative_path ) <EOL> data = pd . read_csv ( fullpath , nrows = ntrain + ntest ) <EOL> X = data [ '<STR_LIT:text>' ] . values <EOL> X = [ str ( x ) for x in X ] <EOL> Y = data [ '<STR_LIT>' ] . values <EOL> trX = X [ : - ntest ] <EOL> teX = X [ - ntest : ] <EOL> trY = Y [ : - ntest ] <EOL> teY = Y [ - ntest : ] <EOL> return trX , teX , trY , teY <EOL> def load_mnist ( data_dir = None ) : <EOL> if data_dir is None : <EOL> import urllib <EOL> import gzip <EOL> url = '<STR_LIT>' <EOL> fnames = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> for fname in fnames : <EOL> if not os . path . isfile ( fname ) : <EOL> print '<STR_LIT>' , fname <EOL> urllib . urlretrieve ( url + fname , fname ) <EOL> data_dir = '<STR_LIT>' <EOL> fd = gzip . open ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> loaded = np . fromstring ( fd . read ( ) , dtype = np . uint8 ) <EOL> trX = loaded [ <NUM_LIT:16> : ] . reshape ( ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> fd = gzip . open ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> loaded = np . fromstring ( fd . read ( ) , dtype = np . uint8 ) <EOL> trY = loaded [ <NUM_LIT:8> : ] . reshape ( ( <NUM_LIT> ) ) <EOL> fd = gzip . open ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> loaded = np . fromstring ( fd . read ( ) , dtype = np . uint8 ) <EOL> teX = loaded [ <NUM_LIT:16> : ] . reshape ( ( <NUM_LIT> , - <NUM_LIT:1> ) ) <EOL> fd = gzip . open ( os . path . join ( data_dir , '<STR_LIT>' ) ) <EOL> loaded = np . fromstring ( fd . read ( ) , dtype = np . uint8 ) <EOL> teY = loaded [ <NUM_LIT:8> : ] . reshape ( ( <NUM_LIT> ) ) <EOL> trX = trX / <NUM_LIT> <EOL> teX = teX / <NUM_LIT> <EOL> trX = trX . reshape ( - <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) <EOL> teX = teX . reshape ( - <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) <EOL> return trX , teX , trY , teY </s>
