Skip to content
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

fixed table layout for McNemar's test #744

Merged
merged 2 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/sources/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The CHANGELOG for the current development version is available at
##### Changes

- `permutation_test` (`mlxtend.evaluate.permutation`) ìs corrected to give the proportion of permutations whose statistic is *at least as extreme* as the one observed. ([#721](https://github.com/rasbt/mlxtend/pull/721) via [Florian Charlier](https://github.com/DarthTrevis))
- Fixes the McNemar confusion matrix layout to match the convention (and documentation), swapping the upper left and lower right cells. ([#744](https://github.com/rasbt/mlxtend/pull/744) via [mmarius](https://github.com/mmarius))

##### Bug Fixes

Expand Down
8 changes: 4 additions & 4 deletions mlxtend/evaluate/mcnemar.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def mcnemar_table(y_target, y_model1, y_model2):
tb = np.zeros((2, 2), dtype=int)

tb[0, 0] = np.sum(plus_true == 2)
tb[0, 1] = np.sum(minus_true == 1)
tb[1, 0] = np.sum(minus_true == -1)
tb[1, 1] = np.sum(plus_true == 0)
tb[1, 0] = np.sum(minus_true == 1)
tb[0, 1] = np.sum(minus_true == -1)

return tb

Expand Down Expand Up @@ -148,9 +148,9 @@ def mcnemar_tables(y_target, *y_model_predictions):
minus_true = model1_vs_true - model2_vs_true

tb[0, 0] = np.sum(plus_true == 2)
tb[0, 1] = np.sum(minus_true == 1)
tb[1, 0] = np.sum(minus_true == -1)
tb[1, 1] = np.sum(plus_true == 0)
tb[1, 0] = np.sum(minus_true == 1)
tb[0, 1] = np.sum(minus_true == -1)

name_str = 'model_%s vs model_%s' % (comb[0], comb[1])
tables[name_str] = tb
Expand Down
8 changes: 4 additions & 4 deletions mlxtend/evaluate/tests/test_mcnemar_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def test_input_binary():
tb = mcnemar_table(y_target=y_target,
y_model1=y_model1,
y_model2=y_model2)
expect = np.array([[4, 1],
[2, 3]])
expect = np.array([[4, 2],
[1, 3]])

np.testing.assert_array_equal(tb, expect)

Expand All @@ -89,7 +89,7 @@ def test_input_nonbinary():
tb = mcnemar_table(y_target=y_target,
y_model1=y_model1,
y_model2=y_model2)
expect = np.array([[4, 1],
[2, 3]])
expect = np.array([[4, 2],
[1, 3]])

np.testing.assert_array_equal(tb, expect)
16 changes: 8 additions & 8 deletions mlxtend/evaluate/tests/test_mcnemar_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ def test_input_binary():
y_model2,
y_model3)

expect1 = np.array([[4, 1],
[2, 3]])
expect1 = np.array([[4, 2],
[1, 3]])

expect2 = np.array([[5, 0],
[1, 4]])
expect2 = np.array([[5, 1],
[0, 4]])

expect3 = np.array([[4, 1],
[1, 4]])
Expand All @@ -121,11 +121,11 @@ def test_input_nonbinary():
y_model2,
y_model3)

expect1 = np.array([[4, 1],
[2, 3]])
expect1 = np.array([[4, 2],
[1, 3]])

expect2 = np.array([[5, 0],
[1, 4]])
expect2 = np.array([[5, 1],
[0, 4]])

expect3 = np.array([[4, 1],
[1, 4]])
Expand Down