예제 #1
0
 def evaluate(self):
     """
     评估单个行为的uAUC值
     """
     if self.stage in ["online_train", "offline_train"]:
         # 训练集,每个action一个文件
         action = self.action
     else:
         # 测试集,所有action在同一个文件
         action = "all"
     file_name = "{stage}_{action}_{day}_concate_sample.csv".format(
         stage=self.stage, action=action, day=STAGE_END_DAY[self.stage])
     evaluate_dir = os.path.join(FLAGS.root_path, self.stage, file_name)
     df = pd.read_csv(evaluate_dir)
     userid_list = df['userid'].astype(str).tolist()
     predicts = self.estimator.predict(
         input_fn=lambda: self.input_fn_predict(df, self.stage, self.action
                                                ))
     # print(file_name)
     # print(predicts)
     predicts_df = pd.DataFrame.from_dict(predicts)
     # logits = predicts_df["logistic"].map(lambda x: x[0])
     print(predicts_df.head())
     logits = predicts_df["logits"].map(lambda x: x[0])
     labels = df[self.action].values
     uauc = uAUC(labels, logits, userid_list)
     return df[["userid", "feedid"]], logits, uauc
 def evaluate(self, df):
     #测试集
     test_x = df[self.select_frts].values
     labels = df[self.action].values
     userid_list = df['userid'].astype(str).tolist()
     logits = self.model.predict(test_x)
     uauc = uAUC(labels, logits, userid_list)
     return df[["userid", "feedid"]], logits, uauc
예제 #3
0
def test(model, data_loader, device):
    model.eval()
    targets, predicts, user_ids = list(), list(), list()
    with torch.no_grad():
        for cat, nu, feed, target in tqdm.tqdm(data_loader,
                                               smoothing=0,
                                               mininterval=1.0):
            cat, nu, feed, target = cat.to(device).long(), nu.to(
                device), feed.to(device), target.to(device)
            y = model(cat, nu.unsqueeze(2), feed)
            user_ids.extend(cat[:, 0].tolist())
            targets.extend(target.tolist())
            predicts.extend(y.tolist())
    return uAUC(targets, predicts, user_ids)
예제 #4
0
 def evaluate(self, x, y, userid_list, batch_size=256):
     """
     :param x: Numpy array of test data (if the model has a single input), or list of Numpy arrays (if the model has multiple inputs).
     :param y: Numpy array of target (label) data (if the model has a single output), or list of Numpy arrays (if the model has multiple outputs).
     :param batch_size: Integer or `None`. Number of samples per evaluation step. If unspecified, `batch_size` will default to 256.
     :return: Dict contains metric names and metric values.
     """
     pred_ans = self.predict(x, batch_size)
     # y=y.reshape(y.shape[0],)
     # pred_ans=pred_ans.reshape(pred_ans.shape[0],)
     uauc = uAUC(y, pred_ans, userid_list)
     print('uauc:', y.shape, pred_ans.shape, uauc)
     eval_result = {}
     eval_result['auc'] = uauc
     return eval_result