<s> import sys <EOL> sys . path . append ( "<STR_LIT>" ) <EOL> from score import user_based_knn , pearson <EOL> from dataset import DataIO <EOL> from model import UserModel <EOL> from suggest import top_ns <EOL> ratings_file = '<STR_LIT>' <EOL> given_users = [ <NUM_LIT> , <NUM_LIT> ] <EOL> NN = <NUM_LIT:5> <EOL> n = <NUM_LIT:3> <EOL> part_1_file = '<STR_LIT>' <EOL> part_2_file = '<STR_LIT>' <EOL> data = DataIO ( ) <EOL> data . load ( ratings_file ) <EOL> model = UserModel ( normalize = False ) <EOL> model . build ( data ) <EOL> given_users = data . translate_users ( given_users ) <EOL> given_items = range ( data . num_items ( ) ) <EOL> R = user_based_knn ( model , NN , given_users , given_items , pearson , promote_users = False ) <EOL> recs = top_ns ( R , n , keep_order = True ) <EOL> file = open ( part_1_file , '<STR_LIT:w>' ) <EOL> file . write ( '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % ( data . old_item_idx ( i ) , s ) for u in recs for ( i , s ) in u ] ) ) <EOL> file . close ( ) <EOL> R = user_based_knn ( model , NN , given_users , given_items , pearson , promote_users = False , exclude_seen = False , normalize = True ) <EOL> recs = top_ns ( R , n , keep_order = True ) <EOL> file = open ( part_2_file , '<STR_LIT:w>' ) <EOL> file . write ( '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % ( data . old_item_idx ( i ) , s ) for u in recs for ( i , s ) in u ] ) ) <EOL> file . close ( ) </s>
