question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Labels are sometimes cut off in ConfusionMatrix

See original GitHub issue

Describe the bug When a dictionary of encoding-to-string mappings is provided to the ConfusionMatrix so that the class names will appear as labels, sometimes the class and axis labels get cut off.

confusion_matrix_iris

To Reproduce

from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split as tts

from yellowbrick.classifier import ConfusionMatrix


iris = load_iris()
iris_X = iris.data
iris_y = iris.target
iris_classes = iris.target_names
i_X_train, i_X_test, i_y_train, i_y_test = tts(
    iris_X, iris_y, test_size=0.2
)
model = LogisticRegression()
iris_cm = ConfusionMatrix(
    model, classes=iris_classes,
    label_encoder={0: 'setosa', 1: 'versicolor', 2: 'virginica'}
)
iris_cm.fit(i_X_train, i_y_train)
iris_cm.score(i_X_test, i_y_test)
i = iris_cm.poof()

Desktop (please complete the following information):

  • OS: macOS
  • Python Version 3.6
  • Yellowbrick Version 0.8

Additional context Note that the behavior appears to be somewhat different when the code is executed inside a Jupyter notebook. Discovered in the process of working on #611

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
lwgraycommented, Feb 14, 2019

I am reopening this issue because during my implementation of plot directive for the ConfusionMatrix Docs #747 I came across it again. It doesn’t appear to be fixed with recent mpl updates.

  • OS: Ubuntu 18.04.1 LTS
  • Python Version 3.6.5
  • Yellowbrick Version 0.9
  • I use Anaconda
  • matplotlib 3.0.2

confusionmatrix-2

1reaction
lwgraycommented, Feb 22, 2019

I think I might have found a partial solution (also at #768). I found that adding the keyword bbox_inches='tight' to poof fixed the cutoff.

iris_cm = ConfusionMatrix(
    model, classes=classes,
    label_encoder={0: 'setosa', 1: 'versicolor', 2: 'virginica'}
)

iris_cm.fit(X_train, y_train)
iris_cm.score(X_test, y_test)

i=iris_cm.poof(bbox_inches='tight')

Before bbox_inches='tight' image

After bbox_inches='tight' image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in Confusion Matrix : the data and reference factors must ...
I had the same issue. I guess it happened because data argument was not casted as factor as I expected. Try: confusionMatrix(pred,as.factor(testing$Final)).
Read more >
Understanding Confusion Matrix | by Sarang Narkhede
Confusion Matrix is a performance measurement for machine learning ... very best of Towards Data Science: from hands-on tutorials and cutting-edge research ...
Read more >
Determining a Cut-Off or Threshold When Working ... - Medium
dfx['DECILE'] = pd.qcut(dfx['P_FAIL'], 10, labels=np.arange(100, 0, -10)) ... Again, a cut-off (threshold) is required to build a confusion matrix.
Read more >
Confusion Matrix for Machine Learning - Analytics Vidhya
There are plenty of ways to gauge the performance of your classification model but none have stood the test of time like the...
Read more >
alternative cut-off confusion matrix - JMP User Community
I have used the alternative cut-off probability confusion matrix add-in many times. Suddenly it is producing nonsensical results on some ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found