parameters: (self, test_loader, metric)
return_statement: return test_metric
docstring: Evaluate the model on the given test dataset.
  
          Parameters
          ----------
          test_loader: Dataloader object for the test dataset.
          metric: Metric used for evaluation (AUC / F1).
docstring_summary: Evaluate the model on the given test dataset.
docstring_tokens: Evaluate the model on the given test dataset .
function: def test(self, test_loader, metric):
          """Evaluate the model on the given test dataset.
  
          Parameters
          ----------
          test_loader: Dataloader object for the test dataset.
          metric: Metric used for evaluation (AUC / F1).
          """        
          self.model.eval()
          label_score = []
          batch_idx = -1
          for data, target, _ in test_loader:
              batch_idx += 1
              data, target = data.to(self.device), target.to(self.device)
              data = data.to(torch.float)
              target = target.to(torch.float)
              target = torch.squeeze(target)
  
              logits = self.model(data)
              logits = torch.squeeze(logits, dim = 1)
              sigmoid_logits = torch.sigmoid(logits)
              scores = logits
              label_score += list(zip(target.cpu().data.numpy().tolist(),
                                              scores.cpu().data.numpy().tolist()))
          # Compute test score
          labels, scores = zip(*label_score)
          labels = np.array(labels)
          scores = np.array(scores)
          if metric == 'F1':
              # Evaluation based on https://openreview.net/forum?id=BJJLHbb0-
              thresh = np.percentile(scores, 20)
              y_pred = np.where(scores >= thresh, 1, 0)
              prec, recall, test_metric, _ = precision_recall_fscore_support(
                  labels, y_pred, average="binary")
          if metric == 'AUC':
              test_metric = roc_auc_score(labels, scores)
          return test_metric
function_tokens: def test ( self , test_loader , metric ) : self . model . eval ( ) label_score = [ ] batch_idx = - 1 for data , target , _ in test_loader : batch_idx += 1 data , target = data . to ( self . device ) , target . to ( self . device ) data = data . to ( torch . float ) target = target . to ( torch . float ) target = torch . squeeze ( target ) logits = self . model ( data ) logits = torch . squeeze ( logits , dim = 1 ) sigmoid_logits = torch . sigmoid ( logits ) scores = logits label_score += list ( zip ( target . cpu ( ) . data . numpy ( ) . tolist ( ) , scores . cpu ( ) . data . numpy ( ) . tolist ( ) ) ) # Compute test score labels , scores = zip ( * label_score ) labels = np . array ( labels ) scores = np . array ( scores ) if metric == 'F1' : # Evaluation based on https://openreview.net/forum?id=BJJLHbb0- thresh = np . percentile ( scores , 20 ) y_pred = np . where ( scores >= thresh , 1 , 0 ) prec , recall , test_metric , _ = precision_recall_fscore_support ( labels , y_pred , average = "binary" ) if metric == 'AUC' : test_metric = roc_auc_score ( labels , scores ) return test_metric