Log inBook a Demo
BuildMidData / MLAuto-graded

Build a confusion matrix and per-class F1

Whether model-quality numbers are genuinely understood, including the cases that quietly distort a reported score, becomes clear quickly.metrics.py computes the numbers every model evaluation reports — a confusion matrix, per-class precision, recall and F1, plus macro and micro averages — from scratch with the standard library only. The shipped version is wrong in four ways, including a hard crash the moment a class is never predicted, and precision and recall swapped in the per-class output.
30 min
python

What it measures

Machine learningKnowing what these metrics mean well enough to notice that two of them are transposed.
PythonImplementing the arithmetic from scratch, including the degenerate denominators.
Handling the empty caseDeciding what a never-predicted class should score, rather than letting it crash the evaluation.

Your environment

Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards

Start this lab

30 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo