-
-
Notifications
You must be signed in to change notification settings - Fork 694
remove sklearn dependency from cohenkappa score calculation logic and applied custom calculation and updated tests #3731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
9c1b2ab
d6782e7
c5eefb0
add7192
8808d09
e80d750
16bcc77
39cc54b
358d4f2
4f64faf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| import os | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| import sklearn | ||
| import torch | ||
| from sklearn.metrics import cohen_kappa_score | ||
|
|
||
|
|
@@ -14,55 +12,15 @@ | |
| torch.manual_seed(12) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def mock_no_sklearn(): | ||
| with patch.dict("sys.modules", {"sklearn.metrics": None}): | ||
| yield sklearn | ||
|
|
||
|
|
||
| def test_no_sklearn(mock_no_sklearn): | ||
| with pytest.raises(ModuleNotFoundError, match=r"This contrib module requires scikit-learn to be installed."): | ||
| CohenKappa() | ||
|
|
||
|
|
||
| def test_no_update(): | ||
| ck = CohenKappa() | ||
|
|
||
| with pytest.raises( | ||
| NotComputableError, match=r"EpochMetric must have at least one example before it can be computed" | ||
| NotComputableError, match=r"CohenKappa must have at least one example before it can be computed" | ||
| ): | ||
| ck.compute() | ||
|
|
||
|
|
||
| def test_input_types(): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here, why do you remove these tests? |
||
| ck = CohenKappa() | ||
| ck.reset() | ||
| output1 = (torch.rand(4, 3), torch.randint(0, 2, size=(4, 3), dtype=torch.long)) | ||
| ck.update(output1) | ||
|
|
||
| with pytest.raises(ValueError, match=r"Incoherent types between input y_pred and stored predictions"): | ||
| ck.update((torch.randint(0, 5, size=(4, 3)), torch.randint(0, 2, size=(4, 3)))) | ||
|
|
||
| with pytest.raises(ValueError, match=r"Incoherent types between input y and stored targets"): | ||
| ck.update((torch.rand(4, 3), torch.randint(0, 2, size=(4, 3)).to(torch.int32))) | ||
|
|
||
| with pytest.raises(ValueError, match=r"Incoherent types between input y_pred and stored predictions"): | ||
| ck.update((torch.randint(0, 2, size=(10,)).long(), torch.randint(0, 2, size=(10, 5)).long())) | ||
|
|
||
|
|
||
| def test_check_shape(): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you remove these tests?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I accidentally commited it i was trying to do something with git and it pushed the commited changes |
||
| ck = CohenKappa() | ||
|
|
||
| with pytest.raises(ValueError, match=r"Predictions should be of shape"): | ||
| ck._check_shape((torch.tensor(0), torch.tensor(0))) | ||
|
|
||
| with pytest.raises(ValueError, match=r"Predictions should be of shape"): | ||
| ck._check_shape((torch.rand(4, 3, 1), torch.rand(4, 3))) | ||
|
|
||
| with pytest.raises(ValueError, match=r"Targets should be of shape"): | ||
| ck._check_shape((torch.rand(4, 3), torch.rand(4, 3, 1))) | ||
|
|
||
|
|
||
| def test_cohen_kappa_wrong_weights_type(): | ||
| with pytest.raises(ValueError, match=r"Kappa Weighting type must be"): | ||
| ck = CohenKappa(weights=7) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.