Skip to content

Commit

Permalink
Update format for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thieu1995 committed Feb 23, 2024
1 parent 747395f commit b776794
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
29 changes: 14 additions & 15 deletions tests/test_comparisons/test_sklearn_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# --------------------------------------------------%

import numpy as np
from permetrics import ClassificationMetric
import pytest
from sklearn.metrics import accuracy_score, f1_score, fbeta_score, precision_score, recall_score

from permetrics import ClassificationMetric


@pytest.fixture(scope="module") # scope: Call only 1 time at the beginning
def data():
Expand All @@ -18,23 +19,23 @@ def data():

# Example one-hot encoded y_true and y_pred
y_true2 = np.array([[0, 1, 0], # Class 1
[1, 0, 0], # Class 0
[0, 0, 1], # Class 2
[0, 1, 0], # Class 1
[0, 0, 1]]) # Class 2
[1, 0, 0], # Class 0
[0, 0, 1], # Class 2
[0, 1, 0], # Class 1
[0, 0, 1]]) # Class 2
y_pred2 = np.array([[0.1, 0.8, 0.1], # Predicted probabilities for Class 1, Class 0, Class 2
[0.7, 0.2, 0.1],
[0.2, 0.3, 0.5],
[0.3, 0.6, 0.1],
[0.1, 0.2, 0.7]])
[0.7, 0.2, 0.1],
[0.2, 0.3, 0.5],
[0.3, 0.6, 0.1],
[0.1, 0.2, 0.7]])
cm2 = ClassificationMetric(y_true=y_true2, y_pred=y_pred2)

y_true3 = np.array([0, 1, 2, 0, 2]) # Class 2
y_pred3 = np.array([[0.1, 0.8, 0.1], # Predicted probabilities for Class 1, Class 0, Class 2
[0.7, 0.2, 0.1],
[0.2, 0.3, 0.5],
[0.3, 0.6, 0.1],
[0.1, 0.2, 0.7]])
[0.7, 0.2, 0.1],
[0.2, 0.3, 0.5],
[0.3, 0.6, 0.1],
[0.1, 0.2, 0.7]])
cm3 = ClassificationMetric(y_true=y_true3, y_pred=y_pred3)
return (y_true1, y_pred1), (y_true2, y_pred2), (y_true3, y_pred3), cm1, cm2, cm3

Expand All @@ -53,7 +54,6 @@ def test_AS(data):
# res32 = accuracy_score(y_true3, y_pred3) # ValueError: Classification metrics can't handle a mix of multiclass and continuous-multioutput targets
# assert res31 == res32


# avg_paras = [None, "macro", "micro", "weighted"]
# outs = (dict, float, float, float)
#
Expand Down Expand Up @@ -105,4 +105,3 @@ def test_RS(data):
res11 = cm1.RS(average="macro")
res12 = recall_score(y_true1, y_pred1, average="macro")
assert res11 == res12

5 changes: 3 additions & 2 deletions tests/test_comparisons/test_sklearn_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
# --------------------------------------------------%

import numpy as np
from permetrics import ClusteringMetric
import pytest
from sklearn.metrics import mutual_info_score, normalized_mutual_info_score, \
adjusted_rand_score, rand_score, \
completeness_score, homogeneity_score, v_measure_score, \
fowlkes_mallows_score, calinski_harabasz_score, davies_bouldin_score
import pytest

from permetrics import ClusteringMetric

np.random.seed(42)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_comparisons/test_sklearn_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# --------------------------------------------------%

import numpy as np
from permetrics import RegressionMetric
import pytest
from sklearn.metrics import explained_variance_score, max_error, mean_absolute_error, \
mean_squared_error, median_absolute_error, r2_score, mean_absolute_percentage_error
import pytest

from permetrics import RegressionMetric


@pytest.fixture(scope="module") # scope: Call only 1 time at the beginning
Expand Down
3 changes: 2 additions & 1 deletion tests/test_features/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# --------------------------------------------------%

import numpy as np
from permetrics import ClassificationMetric
import pytest

from permetrics import ClassificationMetric


@pytest.fixture(scope="module") # scope: Call only 1 time at the beginning
def data():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_features/test_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# --------------------------------------------------%

import numpy as np
from permetrics import ClusteringMetric
import pytest

from permetrics import ClusteringMetric

np.random.seed(42)


Expand Down
7 changes: 4 additions & 3 deletions tests/test_features/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# --------------------------------------------------%

import numpy as np
from permetrics import RegressionMetric
import pytest

from permetrics import RegressionMetric


@pytest.fixture(scope="module") # scope: Call only 1 time at the beginning
def data():
Expand Down Expand Up @@ -510,10 +511,10 @@ def test_NRMSE(data):
def test_RSE(data):
rm1, rm2 = data[0], data[1]
# 1D
res = rm1.RSE(n_paras=5) # 5 data samples
res = rm1.RSE(n_paras=5) # 5 data samples
assert isinstance(res, (float))
# ND
res = rm2.RSE(n_paras=6, multi_output=None) # 6 data samples
res = rm2.RSE(n_paras=6, multi_output=None) # 6 data samples
assert isinstance(res, (float))
res = rm2.RSE(n_paras=6, multi_output="raw_values")
assert isinstance(res, (list, tuple, np.ndarray))
Expand Down

0 comments on commit b776794

Please sign in to comment.