print("logistic loss") trainer.fit() elif params["loss"] == "pairwise": print("pairwise ranking loss") trainer.fit_pairwise_ranking_loss() elif params["loss"] == "pairwise+utility": print("pairwise + utility loss") trainer.fit_pairwise_utility_loss() else: raise ValueError( "loss must be in ['utility', 'logit', 'pairwise', 'pairwise+utility']") users_test = X_test[:, 0].reshape(-1, 1) items_test = X_test[:, 1].reshape(-1, 1) y_test = y_test.reshape(-1, 1) preds = trainer.predict(users=users_test, items=items_test, y=y_test, batch_size=TEST_BATCH_SIZE).reshape(-1, 1) output = pd.DataFrame(np.concatenate((users_test, preds, y_test), axis=1), columns=['user_id', 'pred', 'y_true']) output, hit_ratio, ndcg = get_choice_eval_metrics(output, at_k=params['eval_k']) print("hit ratio: {:.4f}".format(hit_ratio)) print("ndcg: {:.4f}".format(ndcg)) log_output(MODEL_DIR, MODEL_NAME, params, output=[hit_ratio, ndcg])
items_test = X_test[:, 1].reshape(-1,1) y_test = y_test.reshape(-1,1) predictor = Predictor(model=model, batch_size=TEST_BATCH_SIZE, users=users_test, items=items_test, y=y_test, use_cuda=args.cuda, n_items=stats["n_items"]) preds = predictor.predict().reshape(-1,1) output = pd.DataFrame(np.concatenate((users_test, preds, y_test), axis=1), columns = ['user_id', 'pred', 'y_true']) if args.task == "choice": output, hit_ratio, ndcg = get_choice_eval_metrics(output, at_k=EVAL_K) print("hit ratio: {:.4f}".format(hit_ratio)) print("ndcg: {:.4f}".format(ndcg)) else: output, rmse, dcg = get_eval_metrics(output, at_k=EVAL_K) print("rmse: {:.4f}".format(rmse)) print("dcg: {:.4f}".format(dcg))