<s> import sys <EOL> import numpy as np <EOL> import cPickle as pickle <EOL> from sklearn . datasets import load_svmlight_file <EOL> def get_x_y ( filename , name ) : <EOL> ( x , y ) = load_svmlight_file ( filename ) <EOL> x = x . toarray ( ) <EOL> if name == '<STR_LIT>' : <EOL> x = x [ : , <NUM_LIT:1> : ] <EOL> y = y . astype ( '<STR_LIT:int>' ) <EOL> if name != '<STR_LIT>' : <EOL> y -= <NUM_LIT:1> <EOL> return ( x , y ) <EOL> name , filename_train , filename_test = sys . argv [ <NUM_LIT:1> : <NUM_LIT:4> ] <EOL> data = { } <EOL> x , y = get_x_y ( name + '<STR_LIT:/>' + filename_train , name ) <EOL> data [ '<STR_LIT>' ] = x <EOL> data [ '<STR_LIT>' ] = y <EOL> if len ( sys . argv ) > <NUM_LIT:4> : <EOL> filename_val = sys . argv [ <NUM_LIT:4> ] <EOL> x , y = get_x_y ( name + '<STR_LIT:/>' + filename_val , name ) <EOL> data [ '<STR_LIT>' ] = np . vstack ( ( data [ '<STR_LIT>' ] , x ) ) <EOL> data [ '<STR_LIT>' ] = np . append ( data [ '<STR_LIT>' ] , y ) <EOL> data [ '<STR_LIT>' ] = data [ '<STR_LIT>' ] . shape [ <NUM_LIT:0> ] <EOL> assert len ( data [ '<STR_LIT>' ] ) == data [ '<STR_LIT>' ] <EOL> x , y = get_x_y ( name + '<STR_LIT:/>' + filename_test , name ) <EOL> data [ '<STR_LIT>' ] = x <EOL> data [ '<STR_LIT>' ] = x . shape [ <NUM_LIT:0> ] <EOL> data [ '<STR_LIT>' ] = y <EOL> data [ '<STR_LIT>' ] = x . shape [ <NUM_LIT:1> ] <EOL> data [ '<STR_LIT>' ] = len ( np . unique ( y ) ) <EOL> try : <EOL> assert data [ '<STR_LIT>' ] == max ( np . unique ( y ) ) + <NUM_LIT:1> <EOL> except AssertionError : <EOL> print '<STR_LIT>' % np . unique ( y ) <EOL> raise AssertionError <EOL> data [ '<STR_LIT>' ] = False <EOL> print '<STR_LIT>' % ( name , data [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] ) <EOL> pickle . dump ( data , open ( name + '<STR_LIT:/>' + name + "<STR_LIT>" , "<STR_LIT:wb>" ) , protocol = pickle . HIGHEST_PROTOCOL ) </s>
