[Metrics] Partial AUROC
Feature
We currently have an auroc metric implementation.
Can we add an additional max_fpr parameter to enable a partial AUROC implementation?
Motivation
Partial AUROC is often more useful in anomaly detection tasks to evaluate the appropriate portion of the ROC curve,
I stumbled onto Lightning metrics looking for a fast Tensor implementation of sklearn metrics. Since sklearn is heavily used, might be useful to reflect their API for metric implementations.
Heres's the function signature of the sklearn version:
sklearn.metrics.roc_auc_score(y_true, y_score, *, average='macro', sample_weight=None, max_fpr=None, multi_class='raise', labels=None)
Method
According to this code, I will need to filter through the return values from the roc method using max_fpr, before calculating area under the curve.

  
    
      pytorch-lightning/pytorch_lightning/metrics/functional/classification.py
    
    
        Lines 840 to 874
      in
      d79bce1
    
  
  
    

        
          
           def auroc( 
        

        
          
                   pred: torch.Tensor, 
        

        
          
                   target: torch.Tensor, 
        

        
          
                   sample_weight: Optional[Sequence] = None, 
        

        
          
                   pos_label: int = 1., 
        

        
          
           ) -> torch.Tensor: 
        

        
          
               """ 
        

        
          
               Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC) from prediction scores 
        

        
          
            
        

        
          
               Args: 
        

        
          
                   pred: estimated probabilities 
        

        
          
                   target: ground-truth labels 
        

        
          
                   sample_weight: sample weights 
        

        
          
                   pos_label: the label for the positive class 
        

        
          
            
        

        
          
               Return: 
        

        
          
                   Tensor containing ROCAUC score 
        

        
          
            
        

        
          
               Example: 
        

        
          
            
        

        
          
                   >>> x = torch.tensor([0, 1, 2, 3]) 
        

        
          
                   >>> y = torch.tensor([0, 1, 1, 0]) 
        

        
          
                   >>> auroc(x, y) 
        

        
          
                   tensor(0.5000) 
        

        
          
               """ 
        

        
          
               if any(target > 1): 
        

        
          
                   raise ValueError('AUROC metric is meant for binary classification, but' 
        

        
          
                                    ' target tensor contains value different from 0 and 1.' 
        

        
          
                                    ' Multiclass is currently not supported.') 
        

        
          
            
        

        
          
               @auc_decorator(reorder=True) 
        

        
          
               def _auroc(pred, target, sample_weight, pos_label): 
        

        
          
                   return roc(pred, target, sample_weight, pos_label) 
        

        
          
            
        

        
          
               return _auroc(pred=pred, target=target, sample_weight=sample_weight, pos_label=pos_label)