Skip to content

Commit eba4e7b

Browse files
Merge pull request #197 from petrobras/other_improvements
Other improvements
2 parents dc21f11 + ad1cd49 commit eba4e7b

15 files changed

Lines changed: 293 additions & 59 deletions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ThreeWToolkit"
3-
version = "3.1.0"
3+
version = "3.2.0"
44
description = "A modular and open-source AI toolkit for time-series processing, aimed at fault detection and classification in oil well operation"
55
readme = { file = "toolkit/ThreeWToolkit/README.md", content-type = "text/markdown" }
66
license = { text = "Apache-2.0" }

tests/clustering/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/metrics/test_classification.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
recall_score,
1313
f1_score,
1414
roc_auc_score,
15+
matthews_corrcoef,
1516
)
1617

1718

@@ -312,6 +313,89 @@ def test_roc_auc_errors(self, y_true: list, y_pred: list, error_type: type | tup
312313
roc_auc_score(y_true=y_true, y_pred=y_pred)
313314

314315

316+
class TestMatthewsCorrcoef:
317+
@pytest.fixture(scope="class")
318+
def sk_mcc(self):
319+
from sklearn.metrics import matthews_corrcoef
320+
321+
return matthews_corrcoef
322+
323+
def test_binary_classification(self, sk_mcc):
324+
y_true = [1, 1, 0, 0]
325+
y_pred = [1, 0, 0, 0]
326+
327+
expected = sk_mcc(y_true, y_pred)
328+
result = matthews_corrcoef(y_true, y_pred)
329+
330+
assert result == pytest.approx(expected)
331+
332+
def test_multiclass_classification(self, sk_mcc):
333+
y_true = [0, 1, 2, 0, 1, 2]
334+
y_pred = [0, 1, 1, 0, 2, 2]
335+
336+
expected = sk_mcc(y_true, y_pred)
337+
result = matthews_corrcoef(y_true, y_pred)
338+
339+
assert result == pytest.approx(expected)
340+
341+
def test_numpy_arrays(self, sk_mcc):
342+
y_true = np.array([1, 1, 0, 0])
343+
y_pred = np.array([1, 0, 0, 0])
344+
345+
expected = sk_mcc(y_true, y_pred)
346+
result = matthews_corrcoef(y_true, y_pred)
347+
348+
assert result == pytest.approx(expected)
349+
350+
def test_pandas_series(self, sk_mcc):
351+
y_true = pd.Series([1, 1, 0, 0])
352+
y_pred = pd.Series([1, 0, 0, 0])
353+
354+
expected = sk_mcc(y_true, y_pred)
355+
result = matthews_corrcoef(y_true, y_pred)
356+
357+
assert result == pytest.approx(expected)
358+
359+
def test_sample_weight(self, sk_mcc):
360+
y_true = [1, 1, 0, 0]
361+
y_pred = [1, 0, 0, 0]
362+
weights = [1.0, 2.0, 1.0, 1.0]
363+
364+
expected = sk_mcc(
365+
y_true,
366+
y_pred,
367+
sample_weight=weights,
368+
)
369+
370+
result = matthews_corrcoef(
371+
y_true,
372+
y_pred,
373+
sample_weight=weights,
374+
)
375+
376+
assert result == pytest.approx(expected)
377+
378+
def test_mismatched_lengths_raises_value_error(self):
379+
y_true = [1, 0, 1]
380+
y_pred = [1, 0]
381+
382+
with pytest.raises(ValueError):
383+
matthews_corrcoef(y_true, y_pred)
384+
385+
@pytest.mark.parametrize(
386+
"y_true,y_pred",
387+
[
388+
("invalid", [1, 0, 1]),
389+
([1, 0, 1], "invalid"),
390+
(123, [1, 0, 1]),
391+
([1, 0, 1], 123),
392+
],
393+
)
394+
def test_invalid_types_raise_error(self, y_true, y_pred):
395+
with pytest.raises(Exception):
396+
matthews_corrcoef(y_true, y_pred)
397+
398+
315399
class TestInputTypes:
316400
"""Test that metrics work with different input types (lists, numpy, pandas)."""
317401

0 commit comments

Comments
 (0)