<s> from os . path import exists , join <EOL> import numpy as np <EOL> from sklearn import datasets <EOL> from sklearn . utils import shuffle <EOL> import utils <EOL> dataset_dir = "<STR_LIT>" <EOL> def fetch_mnist ( training_ratio = <NUM_LIT> , data_home = "<STR_LIT:.>" ) : <EOL> mnist = datasets . fetch_mldata ( '<STR_LIT>' , data_home = data_home ) <EOL> X , y = shuffle ( mnist . data , mnist . target ) <EOL> splitter = int ( len ( X ) * training_ratio ) <EOL> training = X [ : splitter ] , y [ : splitter ] <EOL> test = X [ splitter : ] , y [ splitter : ] <EOL> return training , test <EOL> def download_mnist ( ) : <EOL> training , test = fetch_mnist ( data_home = dataset_dir ) <EOL> X , y = training <EOL> datasets . dump_svmlight_file ( X , y , join ( dataset_dir , "<STR_LIT>" ) ) <EOL> X , y = test <EOL> datasets . dump_svmlight_file ( X , y , join ( dataset_dir , "<STR_LIT>" ) ) <EOL> def load_mnist ( ) : <EOL> def pick ( X , y ) : <EOL> indices = np . logical_or ( y == <NUM_LIT:0> , y == <NUM_LIT:1> ) <EOL> X = X . todense ( ) <EOL> X = X [ indices ] <EOL> y = y [ indices ] <EOL> y = utils . overwrite_labels ( y ) <EOL> return X , y <EOL> n_features = <NUM_LIT> <EOL> training_path = join ( dataset_dir , "<STR_LIT>" ) <EOL> test_path = join ( dataset_dir , "<STR_LIT>" ) <EOL> if not exists ( training_path ) or not exists ( test_path ) : <EOL> download_mnist ( ) <EOL> X , y = datasets . load_svmlight_file ( training_path , n_features = n_features ) <EOL> training = pick ( X , y ) <EOL> X , y = datasets . load_svmlight_file ( test_path , n_features = n_features ) <EOL> test = pick ( X , y ) <EOL> return training , test <EOL> def make_classification ( ) : <EOL> X , y = datasets . make_classification ( n_samples = <NUM_LIT> , n_features = <NUM_LIT:100> , <EOL> n_classes = <NUM_LIT:2> ) <EOL> y = utils . overwrite_labels ( y ) <EOL> return X , y <EOL> def load_digits ( ) : <EOL> digits = datasets . load_digits ( <NUM_LIT:2> ) <EOL> y = np . array ( digits . target , copy = True ) <EOL> y = utils . overwrite_labels ( y ) <EOL> return digits . data , y </s>
