-
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
3 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
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
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,23 @@ | ||
from pathlib import Path | ||
from typing import Tuple | ||
import numpy as np | ||
import pytest | ||
|
||
from plotsandgraphs import pipeline | ||
|
||
|
||
from .utils import random_data_binary_classifier | ||
|
||
TEST_RESULTS_PATH = Path("tests/test_results/pipeline") | ||
|
||
def test_binary_classification_pipeline(random_data_binary_classifier): | ||
""" | ||
Test binary classification pipeline. | ||
Parameters | ||
---------- | ||
random_data_binary_classifier : Tuple[np.ndarray, np.ndarray] | ||
The simulated data. | ||
""" | ||
y_true, y_score = random_data_binary_classifier | ||
pipeline.binary_classifier(y_true, y_score, save_fig_path=TEST_RESULTS_PATH / "pipeline.png") |
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,25 @@ | ||
from typing import Tuple | ||
import numpy as np | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def random_data_binary_classifier() -> Tuple[np.ndarray, np.ndarray]: | ||
""" | ||
Create random data for binary classifier tests. | ||
Returns | ||
------- | ||
Tuple[np.ndarray, np.ndarray] | ||
The simulated data. y_true, y_score | ||
""" | ||
# create some data | ||
n_samples = 1000 | ||
y_true = np.random.choice( | ||
[0, 1], n_samples, p=[0.4, 0.6] | ||
) # the true class labels 0 or 1, with class imbalance 40:60 | ||
|
||
y_score = np.zeros(y_true.shape) # a model's probability of class 1 predictions | ||
y_score[y_true == 1] = np.random.beta(1, 0.6, y_score[y_true == 1].shape) | ||
y_score[y_true == 0] = np.random.beta(0.5, 1, y_score[y_true == 0].shape) | ||
return y_true, y_score |