I have tried to run ConfusionMatrixDisplay (in python3) which is part of sklearn.metrics, but it is not supported.

How can I make it to work?


Could you share more details about this?

Suppose you have built sklearn from source, is that correct?
If yes, do you use the branch with ConfusionMatrixDisplay implementation?


Hi @AastaLLL,
thanks fior the prompt response.

I actually was wandering whether the library was already implemented but I did not invoked it correctly:
following is a snippet from code that fails:

from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay

oModel = KNeighborsClassifier(n_neighbors=maxK)
vHatY = cross_val_predict(oModel, mX, vY, cv=cv)
mConfusion = confusion_matrix(vY, vHatY)
accuracy = np.mean(vY == vHatY)
DisplayConfusionMatrix(mConfusion, accuracy) <= this one fails.

Though if you’re saying that I can recompile the code please advise how should I do it.


It looks like you can import the sklean correctly.
But meet error when calling DisplayConfusionMatrix?

Could you share what kind of error do you meet when the failure occurs?


the error that I receive upon invoking the DisplayConfusionMatrix function is:

Traceback (most recent call last):
File “/home/nvidia/TIMIT_Exercise/”, line 149, in
DisplayConfusionMatrix(mConfusion, accuracy)
File “/home/nvidia/TIMIT_Exercise/”, line 45, in DisplayConfusionMatrix
ConfusionMatrixDisplay(mConfusion).plot(values_format=‘g’, ax=ax)
NameError: name ‘ConfusionMatrixDisplay’ is not defined

Hope that’ll assist your support.


It seems more related to the custom implementation.
Could you share a workable standalone with us for reproducing?



you could look @ ConfusionMatrixDisplay - #4 by igal.kroyter for snippet of the code.


We test the official sample for ConfusionMatrixDisplay and it can work correctly on Xaiver.

It looks like there is some issue with your custom implementation.
Could you give our example a try?

We install skicit-learn v0.24.2. (449 Bytes)

$ export DISPLAY=:0
$ python3