I am interested in reporting only train and test accuracy as well as confusion matrix (say using sklearn confusionmatrix). How can I do that? The current tutorial only reports train/val accuracy and I am having hard time figuring how to incorporate the sklearn confusionmatrix code there. Link to original tutorial here: https://github.com/bentrevett/pytorch-sentiment-analysis/blob/master/4%20-%20Convolutional%20Sentiment%20Analysis.ipynb
0
votes
1 Answers
0
votes
Very similar to the binary_accuracy function defined in the tutorial, you can implement any metric that you want. All you need is a set of model predictions (preds in this case) and true targets (y).
For example, for confusion matrix, you could do the following:
from sklearn.metrics import confusion_matrix
def compute_confusion_matrix(preds, y):
#round predictions to the closest integer
rounded_preds = torch.round(torch.sigmoid(preds))
return confusion_matrix(y, rounded_preds)