
v1 F1 은 (P 와 R 을 동등 가중). 실무에서는 태스크에 따라:
일반화:
그리고 실제 분류기는 continuous score 를 냄. 고정 threshold 는 불균형 데이터에서 최적이 아닐 수 있음 → 점수 자체를 threshold 로 스윕해 가 최대가 되는 지점 찾기.
np.sort(np.unique(y_score)) → 후보 thresholds.y_pred = (y_score >= threshold) → TP/FP/FN 계산.효율적 구현은 argsort(-y_score) 한 번에 cumulative TP/FP 로 .
함수 fbeta_best_threshold(y_score, y_true, beta) 를 완성하세요.
y_score: 양성 점수, shape (N,).y_true: 0/1 정수 레이블.beta: 양수.(best_threshold, best_fbeta) — 둘 다 Python float.| # | 이름 | 검증 |
|---|---|---|
| 1 | 반환 2-tuple (thr, f) | |
| 2 | 완벽 분리 → fbeta=1.0 (어떤 β 든) | |
| 3 | β=1 → F1 정의와 일치 | |
| 4 | β=2 > 1 → recall 높은 threshold 선호 (작은 threshold) | |
| 5 | β=0.5 < 1 → precision 높은 threshold 선호 (큰 threshold) | |
| 6 | threshold 는 scores 중 하나 또는 min(score)-ε | |
| 7 | sklearn fbeta_score 와 일치 (최적 threshold 에서) |
코드를 작성하고 Run 을 눌러보세요.