How to compute accuracy and precision for each class in text classification task?
I have this:Screenshot 2023-01-27 at 16.55.431428×720 99.2 KBBut I need something like this:precision0      0.9621      0.516
2023-10-30T03:34:10Z
Hello! I want to follow up on this thread - I have been trying to the same thing and I am unable to figure out how to get accuracy and precision for each class in a classification task. Please help!
2023-10-30T05:28:21Z
One approach might be to create your own metric function for that. I’ll write a function for illustration only, I haven’t tested it and its just based on my very flawed understanding. hopefully it will be a good starting point.def compute_metrics(eval_preds):logits, labels = eval_predspredictions = np.argmax(logits, axis=-1)classes = set(labels)  # here I’m assuming that predictions & labels are just simple python lists, made of numbers that represent classes.return {precision: {c: len([0 for i in range(len(predictions)) if predictions[i]==labels[i]==c]) / len([0 for i in range(len(predictions)) if predictions[i]==c] for c in classes}}the weird calculation at the end is super inefficient, but it should make it very obvious what I’m doing. similar code can be written for accuracy/f1 etc.here’s a nice article that has the calculations underlying this:Accuracy, Precision, Recall or F1? | by Koo Ping Shung | Towards Data ScienceI hope this helps!