regs_ui = list(np.float32(eval(regs))) # original_matrix, train_matrix, test_matrix, num_users, num_items \ # = mtl.load_as_matrix(datafile='Data/books_and_elecs_merged.csv') original_matrix \ = mtl.load_original_matrix(datafile='Data/ml-1m/ratings.dat', header=['uid', 'iid', 'ratings', 'time'], sep='::') # original_matrix = mtl.matrix_theshold(original_matrix,threshold=2) original_matrix = mtl.matrix_to_binary(original_matrix, 0) # train_matrix, test_matrix = mtl.matrix_split(original_matrix,n_item_per_user=num_test) train_matrix, test_matrix = mtl.matrix_split(original_matrix, opt='prediction', mode='user', test_size=0.2, random_state=10) gpu_options = tf.GPUOptions(allow_growth=True) with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, intra_op_parallelism_threads=8, inter_op_parallelism_threads=8, gpu_options=gpu_options)) as sess: model = BPRMF(sess, top_K=ndcgk, num_ranking_neg=num_ranking_list - num_test, num_factors=num_factors, regs_ui=regs_ui, lr=lr, epochs=num_epochs,
args = parseArgs() num_epochs, batch_size, \ reg_embs, num_neg, lr, ndcgk, num_factors, num_ranking_list, num_test = \ args.epochs, args.batch_size,\ args.ebregs, args.num_neg, args.lr, args.ndcgk, args.nfactors, args.num_rk, args.ntest reg_embs = list(np.float32(eval(reg_embs))) # original_matrix, train_matrix, test_matrix, num_users, num_items \ # = mtl.load_as_matrix(datafile='Data/books_and_elecs_merged.csv') original_matrix \ = mtl.load_original_matrix(datafile='Data/ml-100k/u.data',header=['uid','iid','ratings','time'],sep='\t') original_matrix = mtl.matrix_to_binary(original_matrix, 0) train_matrix, test_matrix = mtl.matrix_split(original_matrix, opt='ranking', n_item_per_user=num_test) num_users, num_items = original_matrix.shape print("Number of users is {0}".format(num_users)) print("Number of items is {0}".format(num_items)) print("Number of ratings for all is {0}".format(original_matrix.nnz)) print("Number of ratings for training is {0}".format(train_matrix.nnz)) print("Ratings density for training is {0}".format( train_matrix.nnz / (num_users * num_items))) gpu_options = tf.GPUOptions(allow_growth=True) with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, intra_op_parallelism_threads=8, inter_op_parallelism_threads=8, gpu_options=gpu_options)) as sess:
num_epochs, batch_size, lr, topk, num_rk, num_test,\ regs_ui, num_factors, alpha = \ args.epochs, args.batch_size, args.lr, args.ndcgk, args.num_rk, args.ntest,\ args.regs_ui,args.nfactors,args.alpha regs_ui = list(np.float32(eval(regs_ui))) # original_matrix, train_matrix, test_matrix,num_users, num_items \ # = mtl.load_as_matrix(datafile='Data/ml-100k/u.data', header=['uid', 'iid', 'ratings', 'time'], sep='\t') original_matrix \ = mtl.load_original_matrix(datafile='Data/ml-100k/u.data', header=['uid', 'iid', 'ratings', 'time'], sep='\t') original_matrix = mtl.matrix_theshold(original_matrix, threshold=2) train_matrix, test_matrix = mtl.matrix_split(original_matrix, n_item_per_user=num_test) test_matrix = mtl.matrix_to_binary(test_matrix, 0) gpu_options = tf.GPUOptions(allow_growth=True) with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, intra_op_parallelism_threads=8, inter_op_parallelism_threads=8, gpu_options=gpu_options)) as sess: model = WRMF(sess, num_factors=num_factors, regs_ui=regs_ui, alpha=alpha, lr=lr, topk=topk, num_ranking_neg=num_rk - num_test,