Creating a confusion matrix plot
When working with machine learning models, for example, NLP classification models, creating a confusion matrix plot can be a very good tool to see the mistakes that the model makes to then further refine it. The model “confuses” one class for another, hence the name confusion matrix.
After working through this recipe, you will be able to create an SVM model, evaluate it, and then create a confusion matrix visualization that will tell you in detail which mistakes the model makes.
Getting ready
We will create an SVM classifier for the BBC news dataset using the sentence transformer model as the vectorizer. We will then use the ConfusionMatrixDisplay
object to create a more informative confusion matrix. The classifier is the same as in the Chapter 4 recipe Using SVMs for supervised text classification.
The dataset is located at https://github.com/PacktPublishing/Python-Natural-Language-Processing-Cookbook-Second-Edition/tree/main...