-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+4.42 KB
tests/metrics/classifciation/__pycache__/test_roc_curve.cpython-310-pytest-7.4.4.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import numpy as np | ||
|
||
from src.metrics import roc_curve | ||
|
||
|
||
def test_roc_curve_identical_labels(): | ||
y_true = np.array([1, 0, 1, 0, 1]) | ||
y_pred = np.array([1, 0, 1, 0, 1]) | ||
|
||
expected_tpr = np.ones(shape=(9,)) | ||
expected_fpr = np.ones(shape=(9,)) | ||
|
||
tpr, fpr = roc_curve(y_true, y_pred) | ||
|
||
assert np.allclose(expected_tpr, tpr, atol=1e-5, rtol=1e-5) | ||
assert np.allclose(expected_fpr, fpr, atol=1e-5, rtol=1e-5) | ||
|
||
|
||
def test_roc_curve_different_labels(): | ||
y_true = np.array([1, 1, 1, 1, 1]) | ||
y_pred = np.array([0, 0, 0, 0, 0]) | ||
|
||
expected_tpr = np.zeros(shape=(9,)) | ||
expected_fpr = np.zeros(shape=(9,)) | ||
|
||
tpr, fpr = roc_curve(y_true, y_pred) | ||
|
||
assert np.allclose(expected_tpr, tpr, atol=1e-5, rtol=1e-5) | ||
assert np.allclose(expected_fpr, fpr, atol=1e-5, rtol=1e-5) | ||
|
||
|
||
def test_roc_curve_reversed_different_labels(): | ||
y_true = np.array([0, 0, 0, 0, 0]) | ||
y_pred = np.array([1, 1, 1, 1, 1]) | ||
|
||
expected_tpr = np.zeros(shape=(9,)) | ||
expected_fpr = np.zeros(shape=(9,)) | ||
|
||
tpr, fpr = roc_curve(y_true, y_pred) | ||
|
||
assert np.allclose(expected_tpr, tpr, atol=1e-5, rtol=1e-5) | ||
assert np.allclose(expected_fpr, fpr, atol=1e-5, rtol=1e-5) | ||
|
||
|
||
def test_roc_curve_reversed_labels(): | ||
y_true = np.array([1, 0, 1, 0, 1]) | ||
y_pred = np.array([0, 1, 0, 1, 0]) | ||
|
||
expected_tpr = np.zeros(shape=(9,)) | ||
expected_fpr = np.zeros(shape=(9,)) | ||
|
||
tpr, fpr = roc_curve(y_true, y_pred) | ||
|
||
assert np.allclose(expected_tpr, tpr, atol=1e-5, rtol=1e-5) | ||
assert np.allclose(expected_fpr, fpr, atol=1e-5, rtol=1e-5) | ||
|
||
|
||
def test_roc_cruve_all_true(): | ||
y_true = np.array([1, 0, 0, 0, 1]) | ||
y_pred = np.array([1, 1, 1, 1, 1]) | ||
|
||
expected_tpr = np.ones(shape=(9,)) | ||
expected_fpr = np.zeros(shape=(9,)) | ||
|
||
tpr, fpr = roc_curve(y_true, y_pred) | ||
|
||
assert np.allclose(expected_tpr, tpr, atol=1e-5, rtol=1e-5) | ||
assert np.allclose(expected_fpr, fpr, atol=1e-5, rtol=1e-5) | ||
|
||
|
||
def test_roc_curve_equal_prob(): | ||
y_true = np.array([1, 0, 0, 0, 1]) | ||
y_pred = np.array([0.5, 0.5, 0.5, 0.5, 0.5]) | ||
|
||
expected_tpr = np.array([1, 1, 1, 1, 1, 0, 0, 0, 0]) | ||
expected_fpr = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1]) | ||
|
||
tpr, fpr = roc_curve(y_true, y_pred) | ||
|
||
assert np.allclose(expected_tpr, tpr, atol=1e-5, rtol=1e-5) | ||
assert np.allclose(expected_fpr, fpr, atol=1e-5, rtol=1e-5) | ||
|
||
|
||
def test_roc_curve_close_to_target(): | ||
y_true = np.array([1, 0, 0, 0, 1]) | ||
y_pred = np.array([0.9, 0.1, 0.1, 0.1, 0.9]) | ||
|
||
expected_tpr = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1]) | ||
expected_fpr = np.array([0, 1, 1, 1, 1, 1, 1, 1, 1]) | ||
|
||
tpr, fpr = roc_curve(y_true, y_pred) | ||
|
||
assert np.allclose(expected_tpr, tpr, atol=1e-5, rtol=1e-5) | ||
assert np.allclose(expected_fpr, fpr, atol=1e-5, rtol=1e-5) |