Fix unreadable labels in plot_confusion_matrix in case of imbalanced data and show_normed=True #504
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change
If show_normed is True, use the normed conf mat for background coloring instead of the absolute conf matrix, because label coloring (black/white) also follows normed conf matrix. This fixes unreadable labels that can occur with imbalanced datasets.
Description
If arg
show_absolute=True
andshow_normed=True
the background-color is choosen by the absolute value, while the label color is chosen by the normed value. This can lead to unreadable labels for imbalanced dataset.Before / After:
![Example](https://camo.githubusercontent.com/0f937d7f2bbda9539a513e26ce89f65f8d348fb49925a1bb38c782194002def5/68747470733a2f2f737472617475732e7069636e69636f2e64652f617070732f66696c65735f73686172696e672f7075626c6963707265766965772f6b716a435a443551734a6e6d3533483f783d3138343626793d37343726613d747275652666696c653d6578616d706c652e706e67267363616c696e6775703d30)
Related issues or pull requests
n/a
Pull Request Checklist
./docs/sources/CHANGELOG.md
file (if applicable)./mlxtend/*/tests
directories (if applicable)mlxtend/docs/sources/
(if applicable)nosetests ./mlxtend -sv
and make sure that all unit tests pass (for small modifications, it might be sufficient to only run the specific test file, e.g.,nosetests ./mlxtend/classifier/tests/test_stacking_cv_classifier.py -sv
)flake8 ./mlxtend