코드 3-7 ROC 곡선을 그리고 AUC를 계산하는 코드

    function drawROC(targets, probs, epoch) {
      return tf.tidy(() => {

     

    수동으로 일련의 확률 임계값을 선택합니다.
        const thresholds = [
          0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45,  
          0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85,             
          0.9, 0.92, 0.94, 0.96, 0.98, 1.0                        
        ];

     

        const tprs = [];  // 진짜 양성 비율
        const fprs = [];  // 거짓 양성 비율
        let area = 0;
        for (let i = 0; i < thresholds.length; ++i) {
          const threshold = thresholds[i];

     

    임계값을 사용해 확률을 예측으로 바꿉니다.
          const threshPredictions =                         
                   utils.binarize(probs, threshold).as1D();

     

    falsePositiveRate() 함수는 예측과 실제 타깃을 비교하여 거짓 양성 비율을 계산합니다. 이 함수는 같은 파일에 정의되어 있습니다.
          const fpr = falsePositiveRate(  
                   targets,
          threshPredictions).arraySync();   

     

          const tpr = tf.metrics.recall(targets, threshPredictions).arraySync();      fprs.push(fpr);
          tprs.push(tpr);

     

    AUC 계산을 위해 면적을 누적합니다.
          if (i > 0) {                                                      
            area += (tprs[i] + tprs[i - 1]) * (fprs[i - 1] - fprs[i]) / 2;  
          }

     

        }
        ui.plotROC(fprs, tprs, epoch);
        return area;
      });
    }
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.