Confusion Matrix from tabular data

Hello, I trained a tabular_learner and would like to visualise my validation results with a confusion matrix.
I tried accessing the data with learn.show_results but that’s not all my results + its a NoneType.
I then tried calling

preds,y,losses = learn.get_preds(with_loss=True)
interp = ClassificationInterpretation(learn, preds, y, losses)

But getting error

TypeError: init() missing 2 required positional arguments: ‘decoded’ and ‘losses’


interp = ClassificationInterpretation.from_learner(learn)

Thank you, that worked! May you care to explain why we passed learn object to it?

Because we are building it from_learner :slight_smile:

This is a factory method for ease of use. Otherwise you’d need to do:

inp, preds, targs, decoded, losses = learn.get_preds(dl=dl, with_input=True, with_loss=True, with_decoded=True, act=None)
interp = ClassificationInterpretation(dl, inp, preds, targs, decoded, losses)

(this is what the from_learner does in the background)
As you can see, one is much easier to use than the other :smiley:

You can also do something like:

dl = learn.dls.test_dl(data, with_labels=True)
interp = ClassificationInterpretation.from_learner(learn, dl=dl)

For when you have custom DataLoaders to use

1 Like

Hi, I am trying to generate a confusion matrix from tabular using:

interp = ClassificationInterpretation.from_learner(learn)

And I get this error:

AttributeError: vocab

I have the same issue, tried all your suggestions none worked