diff --git a/GMF.py b/GMF.py index 8471310..c0f4ba3 100644 --- a/GMF.py +++ b/GMF.py @@ -91,7 +91,7 @@ def get_train_instances(train, num_negatives): # negative instances for t in xrange(num_negatives): j = np.random.randint(num_items) - while train.has_key((u, j)): + while (u, j) in train: j = np.random.randint(num_items) user_input.append(u) item_input.append(j) @@ -168,4 +168,4 @@ def get_train_instances(train, num_negatives): print("End. Best Iteration %d: HR = %.4f, NDCG = %.4f. " %(best_iter, best_hr, best_ndcg)) if args.out > 0: - print("The best GMF model is saved to %s" %(model_out_file)) \ No newline at end of file + print("The best GMF model is saved to %s" %(model_out_file)) diff --git a/MLP.py b/MLP.py index 70566c7..d578826 100644 --- a/MLP.py +++ b/MLP.py @@ -99,7 +99,7 @@ def get_train_instances(train, num_negatives): # negative instances for t in xrange(num_negatives): j = np.random.randint(num_items) - while train.has_key((u, j)): + while (u, j) in train: j = np.random.randint(num_items) user_input.append(u) item_input.append(j) diff --git a/NeuMF.py b/NeuMF.py index be04d53..d3e5b58 100644 --- a/NeuMF.py +++ b/NeuMF.py @@ -143,7 +143,7 @@ def get_train_instances(train, num_negatives): # negative instances for t in xrange(num_negatives): j = np.random.randint(num_items) - while train.has_key((u, j)): + while (u, j) in train: j = np.random.randint(num_items) user_input.append(u) item_input.append(j)