<s> import numpy as np <EOL> from warp import WARPMFRecommender <EOL> from model . warp2 import WARP2 <EOL> class WARP2MFRecommender ( WARPMFRecommender ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . d , self . gamma , self . C ) <EOL> def fit ( self , train , item_features = None ) : <EOL> """<STR_LIT>""" <EOL> max_iters , validation_iters , validation = self . create_validation_set ( train ) <EOL> model = WARP2 ( self . d , self . gamma , self . C , max_iters , validation_iters , self . batch_size , self . positive_thresh , self . max_trials ) <EOL> self . description = '<STR_LIT>' . format ( model ) <EOL> model . fit ( train , item_features , validation ) <EOL> self . U = model . U_ <EOL> self . V = model . V_ <EOL> self . W = model . W_ <EOL> def predict_ratings ( self , users = None , item_features = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( users , int ) : <EOL> users = [ users ] <EOL> if users is None : <EOL> U = self . U <EOL> else : <EOL> U = np . asfortranarray ( self . U [ users , : ] ) <EOL> return U . dot ( self . V . T + item_features . dot ( self . W ) . T ) <EOL> def main ( file_format , filepath , feature_format , feature_file , outfile ) : <EOL> from mrec import load_sparse_matrix , save_recommender <EOL> from mrec . sparse import fast_sparse_matrix <EOL> train = load_sparse_matrix ( file_format , filepath ) <EOL> X = load_sparse_matrix ( feature_format , feature_file ) . toarray ( ) <EOL> num_items = train . shape [ <NUM_LIT:1> ] <EOL> X = X [ : num_items , : ] <EOL> model = WARP2MFRecommender ( d = <NUM_LIT:100> , gamma = <NUM_LIT> , C = <NUM_LIT> , batch_size = <NUM_LIT:10> ) <EOL> model . fit ( train , X ) <EOL> save_recommender ( model , outfile ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> file_format = sys . argv [ <NUM_LIT:1> ] <EOL> filepath = sys . argv [ <NUM_LIT:2> ] <EOL> feature_format = sys . argv [ <NUM_LIT:3> ] <EOL> feature_file = sys . argv [ <NUM_LIT:4> ] <EOL> outfile = sys . argv [ <NUM_LIT:5> ] <EOL> main ( file_format , filepath , feature_format , feature_file , outfile ) </s>
