본문 바로가기

AI/이론

[ML] Precision-Recall Curves

PR Curve of a Bad Model

 

Complete Guide to Understanding Precision and Recall Curves

Precision is defined as the fraction of the relevant positives out of the retrieved ones. Recall is defined as the fraction of retrieved positives out of the relevant ones. 

analyticsindiamag.com

 

Precision-Recall Curves 설명 및 그리기(구현)-Python

Precision-Recall Curves 설명 및 그리기(구현)-Python Goal 이 페이지에서는 Precision-Recall Curve가 무엇이고, 어떻게 그려지는지 알아보겠습니다. 이를 위해서 필요하다고 생각되는 Precision과 Recall, 그리고 Th

ardentdays.tistory.com

Precision-Recall Curve Plot Example

다음은 위의 과정을 설명하기 위한 예시입니다. True Label에 Positive, Negative가 각각 10개씩 있습니다.

1. Probability를 기준으로 내림차순으로 정렬합니다.

2. Threshold를 가장 높은 Probability인 0.9로 정합니다.

3. Threshold값에 따른 Model의 예측값을 정합니다. (현재 TH=0.9)

   Probability >= Threshold이면 Positive로 Predict 합니다.

   Probability <   Threshold이면 Negative로 Predict 합니다.

 

4. Precision과 Recall 값을 구해 Precision-Recall Curve에 Plot합니다.

   Recall   = 실제 Positive를 Positive로 예측 / 실제 Positive

   Precision = Positive로 예측한 것이 실제 Positive / Positive로 예측

 

   Recall     = 110  = 0.1

   Precision = 11   = 1

   Plot ( 0.1, 1 )

 

5. Threshold를 현재 Probability보다 한 단계 낮은 값으로 정하고 3번으로 돌아갑니다. Threshold = 0.8

 

 

 

 

 

 

 

 

 

 

3. Threshold값에 따른 Model의 예측값을 정합니다. (현재 TH=0.8)

   Probability >= Threshold이면 Positive로 Predict 합니다.

   Probability <   Threshold이면 Negative로 Predict 합니다.

 

4. Precision과 Recall 값을 구해 Precision-Recall Curve에 Plot합니다.

   Recall   = 실제 Positive를 Positive로 예측 / 실제 Positive

   Precision = Positive로 예측한 것이 실제 Positive / Positive로 예측

 

   Recall     = 210  = 0.2

   Precision = 22   = 1

   Plot ( 0.2 ,1 )

 

5. Threshold를 현재 Probability보다 한 단계 낮은 값으로 정하고 3번으로 돌아갑니다. Threshold = 0.7

 

 

 

 

 

 

 

 

3. Threshold값에 따른 Model의 예측값을 정합니다. (현재 TH=0.7)

   Probability >= Threshold이면 Positive로 Predict 합니다.

   Probability <   Threshold이면 Negative로 Predict 합니다.

 

4. Precision과 Recall 값을 구해 Precision-Recall Curve에 Plot합니다.

   Recall   = 실제 Positive를 Positive로 예측 / 실제 Positive

   Precision = Positive로 예측한 것이 실제 Positive / Positive로 예측

 

   Recall     = 210  = 0.2

   Precision = 23   = 0.67

   Plot ( 0.2, 0.67 )

 

5. Threshold를 현재 Probability보다 한 단계 낮은 값으로 정하고 3번으로 돌아갑니다. Threshold = 0.6

 

 

 

 

 

 

 

 

이러한 과정을 반복하여 Threshold = 0.1까지 진행합니다.

3. Threshold값에 따른 Model의 예측값을 정합니다. (현재 TH=0.1)

   Probability >= Threshold이면 Positive로 Predict

   Probability <   Threshold이면 Negative로 Predict 합니다.

 

4. Precision과 Recall 값을 구해 Precision-Recall Curve에 Plot합니다.

   Recall     = 실제 Positive를 Positive로 예측 / 실제 Positive

   Precision = Positive로 예측한 것이 실제 Positive / Positive로 예측

 

   Recall     = 1010  = 1

   Precision = 1020   = 0.5

   Plot ( 1 , 0.5 )

 

5. 현재 Threshold보다 낮은 Probaility(or Scroe)가 없어 종료합니다.

 

 

위의 과정 중에 나온 Recall, Precision 을 Plot하면 다음과 같은 Precision-Recall Curve가 그려지게 됩니다.

 

 

추론 결과 나온 conf점수를 내림차순으로 만들어 놓음

conf점수를 threshold로 하면 recall값은 20개 중에 그 만큼 수치로 지정됨

precision은 나머지는 모두 negative가 됨

임계치 낮아지면 모두가 positive -> precision은 떨어짐, recall은 모두 positive이므로 그 중에 실제 정답인건 모두 들어있음

 

 

'AI > 이론' 카테고리의 다른 글

[ML] Winograd convolution layer  (0) 2022.12.12
[ML] Focal Loss  (0) 2022.12.08
[ML] DCN, Deformable Convolution Networks  (0) 2022.01.04
[ML] AutoEncoder  (0) 2022.01.04
[ML] 분류 성능 평가 지표  (0) 2022.01.02