Вычислите AUC-ROC (Area Under the Receiver Operating Characteristic Curve) с нуля, используя трапецоидальный метод.
- TPR (True Positive Rate) = TP / P
- FPR (False Positive Rate) = FP / N
- AUC = Σ (FPR[i] - FPR[i-1]) × (TPR[i] + TPR[i-1]) / 2
Верните AUC-ROC, округлённый до 4 знаков.
def auc_roc(y_true: list[int], y_scores: list[float]) -> float:
auc_roc([1, 1, 0, 0], [0.9, 0.8, 0.3, 0.1]) → 1.0
auc_roc([1, 0, 1, 0], [0.9, 0.8, 0.2, 0.1]) → 0.75
- 2 ≤ n ≤ 10⁴
- y_true ∈ {0, 1}
- 0 ≤ score ≤ 1
- Хотя бы один 0 и один 1 в y_true
y_true = [1,1,0,0]y_scores = [0.9,0.8,0.3,0.1]1y_true = [1,0,1,0]y_scores = [0.9,0.8,0.2,0.1]0.75y_true = [0,0,1,1]y_scores = [0.9,0.8,0.3,0.1]0