-
카테고리
-
세부 분야
딥러닝 · 머신러닝
-
해결 여부
미해결
roc_curve 함수에서 반환하는 fpr, tpr, threshold의 갯수를 늘려줄 수 있을까요?
21.05.27 21:33 작성 조회수 762
0
안녕하세요. 먼저 테스트 데이터가 그렇게 많지는 않습니다. 그런 상태에서 roc_curve 평가지표를 찍어봤을 때 index 개수가 얼마 나오지 않아서 질문을 드립니다. 그래서 그런지 threshold가 조금 최적화가 덜되는 것 같아서요
distances = (tpr - 1.) ** 2 + fpr ** 2 # distances from (1,0) in roc curve
best_index = np.argmin(distances)
#그래서 주석이 아닌 아래 threshold 값을 쓰고 있습니다
threshold = (thresholds[best_index] + thresholds[best_index +1]) / 2
# threshold = thresholds[best_index]
답변을 작성해보세요.
0
권 철민
지식공유자2021.05.28
안녕하십니까,
수동으로 조절할수 없는 것으로 알고 있습니다.
threasholds의 갯수는 최소한 predict 확률의 unique한 갯수 + 1만큼 만들어 집니다.
그러니까 predict 확률이 [0.1, 0.1, 0.1, 0.1, 0.2] 로 다섯개 값이 있어도 고유한 값은 0.1, 0.2 두개이므로 thresholds는 3개가 만들어집니다.
아래 코드로 테스트 해보시면 됩니다.
import numpy as np
from sklearn.metrics import roc_curve
y = np.array([1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 7])
predict_proba = np.array([0.1, 0.4, 0.35, 0.8, 0.4, 0.5, 0.8, 0.35, 0.4, 0.35, 0.8, 0.8])
fpr, tpr, thresholds = roc_curve(y, predict_proba , pos_label=2)
print('thresholds:', thresholds)
print('unique predict proba:', np.unique(scores))
답변 1