Precision-Recall Tradeoff: Best Threshold

Xem dạng PDF

Gửi bài giải

Điểm: 100,00
Giới hạn thời gian: 2.0s
Giới hạn bộ nhớ: 256M

Tác giả:
Dạng bài
Ngôn ngữ cho phép
Python

Task

Given binary true labels and predicted probability scores, sweep thresholds t ∈ {0.1, 0.2, …, 0.9} and find the threshold that maximises F1. Classify as positive if score >= t. Break ties by choosing the smallest threshold.

Input

  • Line 1: integer n
  • Line 2: n space-separated ints (true labels: 0 or 1)
  • Line 3: n space-separated floats (predicted scores in [0, 1])

Output

Two space-separated values: best_threshold best_f1

Example

Input:

6
1 0 1 1 0 1
0.9 0.1 0.8 0.6 0.4 0.7

Output:

0.6 0.8888888889

Scaffolding

def best_threshold(labels: list[int], scores: list[float]) -> tuple: ...

Notes

Track M: use NumPy vectorised threshold sweeping. Studying this reveals the precision–recall tradeoff: higher threshold → higher precision, lower recall.


Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.