A classifier on 1,000 test examples has TP = 10, FN = 10, FP = 5 and TN = 975. Compute the accuracy, the F1 score and the Matthews correlation coefficient, MCC=TP⋅TN−FP⋅FN(TP+FP)(TP+FN)(TN+FP)(TN+FN). What do these give for a model that always predicts negative?

ML systems and evaluation, Classification metrics
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can compute MCC from a confusion matrix and explain why it is more informative than accuracy on imbalanced data.

Key idea

MCC=TP⋅TN−FP⋅FN(TP+FP)(TP+FN)(TN+FP)(TN+FN), where TP,FN,FP,TN are true positives, false negatives, false positives and true negatives. It is the correlation between predicted and true labels, from −1 to +1, and uses all four cells.

Steps

  1. Compute accuracy: (10+975)/1000=0.985. This looks high, yet only 2% of the examples are positive.
  2. Compute precision, recall and F1: precision =10/15≈0.667, recall =10/20=0.500, so F1=2⋅10/(2⋅10+5+10)=20/35≈0.571.
  3. Compute MCC: the numerator is 10×975−5×10=9,750−50=9,700, and the denominator is 15×20×980×985=289,590,000≈17,017.3, giving MCC≈9,700/17,017.3≈0.570.
  4. Evaluate the always-negative model (TP=FP=0, FN=20, TN=980): accuracy is 980/1000=0.980 (only 0.5 percentage points below our model), while recall and F1 drop to 0.
  5. Evaluate MCC for the always-negative model: the factor TP+FP=0 makes the denominator zero, so by convention MCC is set to 0 (no better than chance), matching intuition since the model learnt nothing.
  6. Compare the metrics: accuracy barely separates a useful model from a trivial one (0.985 vs 0.980), whereas MCC separates them clearly (0.570 vs 0) and, unlike F1, also rewards correct negatives so it treats both classes symmetrically.

Common mistakes

How long your answer should be

Half a page; 4 minutes.

Read this

Previous in ML systems and evaluation: Two classifiers A and B are evaluated on the same 200 test examples. Both are right on 150, both are wrong on 15, only A is right on 25 and only B is right on 10. Test at the 5% level, using McNemar's statistic χ2=(b−c)2/(b+c) (where b and c count the examples on which only one of the two classifiers is right) and the 5% critical value 3.84, whether the difference in accuracy is real. Why not simply compare the two accuracies?
Next in ML systems and evaluation: How do you evaluate the retriever in a RAG (retrieval-augmented generation) system separately from the generator? Suppose three queries have relevant chunk IDs R1={c2,c5}, R2={c8,c9,c10} and R3={c12}, and the retriever returns top-5 lists L1=[c1,c2,c4,c5,c7], L2=[c8,c1,c3,c6,c11] and L3=[c3,c4,c7,c9,c15]. What are the recall@5, precision@5, hit rate@5 and MRR (mean reciprocal rank), and how does scoring both retrieval and generation let you separate a retrieval miss from a generation error?