0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09Is 92.5% accuracy good?
Brightcart's full churn model has been tested on two hundred customers, and it's ninety-two point five percent accurate. Meera is ready to celebrate. But meet a second model. It's lazy. It doesn't look at the data at all. It just says "this customer stays", every single time. Its accuracy? Ninety percent. How? Because only twenty of these two hundred customers actually leave. Saying "stays" is right a hundred and eighty times. But it catches none of the customers we care about. So is ninety-two point five percent good?
We can't tell yet, because accuracy alone hides exactly what matters. Today we'll learn the tools professionals use instead. Season One, Module Four, stop two: how to measure a classifier.
1:04The confusion matrix
The fix starts with a simple table called the confusion matrix. It shows how a model is right and how it's wrong. For churn, we call "leaves" the positive class, the thing we're trying to detect. Every customer lands in one of four boxes. True positives: they left, and the model predicted it. Fifteen. False negatives: they left, but the model missed them. Five. False positives: they stayed, but the model raised a false alarm. Ten. And true negatives: they stayed, and the model correctly said so. A hundred and seventy.
Here's a trick for the names. The second word, positive or negative, is what the model said. The first word, true or false, is whether it was right. Accuracy is the share of all predictions that were right: fifteen plus a hundred and seventy, out of two hundred. Ninety-two point five percent. And the lazy model, side by side: zero true positives, twenty misses, ninety percent accuracy. Now we can see what accuracy was hiding.
2:11Precision and recall
From the confusion matrix come the two most important numbers in classification. Precision asks: when the model says "this customer is leaving", how often is it right? Look only at the predicted-leave column: fifteen correct out of twenty-five alarms. Precision is sixty percent. For Sana, that's how many coupons go to customers who really were leaving. Recall asks: of all the customers who actually left, how many did we catch? Look only at the actually-left row: fifteen out of twenty. Recall is seventy-five percent.
That's how many leavers Sana gets a chance to rescue. You'll also hear recall called sensitivity, or the true positive rate. And there are mirror-image measures for the negative class: specificity, the share of stayers correctly left alone, ninety-four percent here; and the false positive rate, one minus that, about five and a half percent. And look at the lazy model now: recall zero. It doesn't catch a single leaver. The confusion matrix exposes it instantly. Remember the fraud alarm from episode four? It had ninety-five percent recall but only about nineteen percent precision.
When positives are rare, precision suffers, and accuracy hides it.
3:34The precision–recall trade-off
Precision and recall pull against each other, and the threshold is the rope between them. Picture fishing for the twenty red fish in a lake of two hundred. A small, careful net catches only a few, but they're all red: high precision, low recall. A giant net catches every red fish, plus a lot of grey ones: high recall, low precision. The threshold is the size of the net. Let's slide it on Brightcart's ten-customer model. At zero point eight, it flags four customers, all of whom really left. Precision is perfect, but it misses one.
At zero point five, still four caught, but now one false alarm. Pause and predict: if we lower it to zero point three, what happens to recall? Recall rises to a hundred percent. Every leaver is caught. And precision even rises slightly, to eighty-three percent, because no extra stayer gets caught: still just one. Which side to favour depends on the cost of each mistake. In medical screening, missing a disease is terrible, so we push for recall. For a spam filter, throwing away an important email is worse than letting one spam through, so we push for precision.
4:59F1 score
Sometimes we want one number that balances precision and recall. The standard choice is the F1 score: two times precision times recall, divided by precision plus recall. For Brightcart's model: zero point six seven. Why not just average them? Because an average can be fooled. A model with perfect precision but two percent recall would average fifty-one percent, which sounds fine. But its F1 is under four percent. F1 uses what's called a harmonic mean, which is dragged down by whichever of the two is weak. So you only get a high F1 if both precision and recall are good.
And if recall matters more than precision for your problem, there's a weighted version called F-beta.
5:48The ROC curve
Precision and recall describe one threshold. But a model's probabilities support every threshold. To see them all at once, we draw a ROC curve. For each threshold, plot the false positive rate across and the true positive rate up. Start with a threshold so high that nobody is flagged: zero and zero, the bottom-left corner. Lower it step by step: each time we pass a customer who really left, the curve steps up; each time we pass a stayer, it steps right. Lower it all the way and everyone is flagged: the top-right corner.
A model that guesses at random walks along the diagonal. A perfect model shoots straight up the left edge to the top before moving right. The closer the curve hugs the top-left corner, the better the model separates the two classes.
6:42AUC explained
The area under the ROC curve, called the A-U-C, summarises the whole curve in one number. Brightcart's model scores zero point nine six. But what does that actually mean? Here's the most intuitive explanation. Take every possible pair of one customer who left and one who stayed. With five of each, that's twenty-five pairs. For each pair, ask: did the model give the leaver a higher score than the stayer? It gets twenty-four of the twenty-five right. Twenty-four out of twenty-five is zero point nine six. That's exactly the A-U-C.
So the A-U-C is the probability that the model ranks a random positive above a random negative. Zero point five is a coin flip. One is a perfect ranking. Two cautions. A-U-C measures ranking, not whether the probabilities are calibrated, and it doesn't tell you which threshold to use. And when positives are very rare, a precision–recall curve often tells you more, because the false positive rate can look tiny even when false alarms swamp your team.
7:53Choosing the threshold with costs
So how should Sana actually choose the threshold? With money, not with habit. Suppose a wasted coupon costs five dollars, and losing a customer costs about sixty dollars in future profit. Mistakes aren't equal: a missed leaver is twelve times worse than a false alarm. Under simple assumptions, that the probabilities are well calibrated and that a coupon always keeps a customer, a coupon is worth sending whenever the expected saving, sixty dollars times the chance of leaving, beats its five-dollar cost: five over sixty, about eight percent.
Episode four assumed the coupon only worked half the time, which gave seventeen percent; here we assume it always works. So Sana should send a coupon to anyone with more than about an eight percent chance of leaving, far below the default fifty percent. The model didn't change. Only the decision rule did. Separating "how likely?" from "what should we do?" is one of the most useful habits in applied machine learning.
9:00More than two classes
With more than two classes, like mugs, lamps and kettles, the confusion matrix simply grows: correct predictions sit on the diagonal, and off-diagonal cells reveal exactly which classes get mixed up. We can compute precision and recall for each class, then average them, either giving every class equal weight, called macro averaging, or pooling all the counts, called micro averaging, where big classes count for more.
9:28Try it yourself: a spam filter's report card
Here's a report for you to grade. A spam filter is tested on a thousand reviews. It correctly flags forty spam reviews, wrongly flags ten genuine ones, misses twenty spam reviews, and correctly passes nine hundred and thirty genuine ones. Work out the accuracy, precision, recall and F1. Pause now.
Accuracy: forty plus nine hundred and thirty, out of a thousand, ninety-seven percent. Precision: forty correct out of fifty flags, eighty percent. Recall: forty caught out of sixty spam reviews, about sixty-seven percent. F1: two times zero point eight times zero point six seven, divided by their sum, about zero point seven three. Notice the story. Ninety-seven percent accuracy sounds superb, but it mostly comes from the many easy genuine reviews. Recall reveals that a third of the spam is getting through. Which number matters depends on Brightcart's goal.
10:35Precision–recall curves
We drew a ROC curve earlier. There's another view of the same threshold sweep, plotting precision against recall. As the threshold drops, recall rises and precision usually falls, tracing a curve. The area under it is called average precision, and you'll meet it again in object detection. When the positive class is rare, like fraud, this view is often more honest. Because there are so many negatives, the false-positive rate can look tiny while the actual number of false alarms still overwhelms the team. The precision–recall curve shows that cost directly.
A good habit: use ROC for overall ranking quality, and precision–recall when positives are rare.
11:21Log loss as a metric
Accuracy, precision and recall only care which side of the threshold a prediction falls on. But two models can make the same decisions with very different confidence. Imagine one model gives every leaver fifty-five percent and every stayer forty-five, while another gives leavers ninety-five and stayers five. At a fifty percent threshold, they're equally accurate. But the second is far more useful for ranking and for decisions based on probability. Log loss, the cross-entropy from logistic regression, captures that difference: it rewards confident correct predictions and heavily punishes confident mistakes.
When your decisions depend on probabilities, track log loss and calibration alongside the usual metrics.
12:11Choosing metrics with the business
In practice, the most important step happens before any modelling: agreeing with the business on what to measure. For churn coupons, Sana cares about catching leavers at an acceptable rate of wasted coupons, and ultimately about profit. For a fraud review queue, the team can only check so many orders a day, so precision among the top few dozen flagged matters most. For hiding spam reviews, precision comes first, because hiding a genuine review annoys a real customer. For routing tickets to teams, macro-averaged F1 makes sure small teams aren't ignored.
Write the chosen metric, and the logic for the threshold, down before you build. It prevents a lot of arguments later.
12:59Comparing two classifiers fairly
Finally, comparing classifiers fairly. Suppose one model has higher recall and the other higher precision. Neither is simply "better"; the right choice depends on what each mistake costs. Compare them on exactly the same test data, using the same rule for choosing thresholds, or compare their whole curves. Check performance on important subgroups. And remember that a difference of a point or two on a small test set may just be noise. In Season Four, we'll learn the statistics to tell real differences from lucky ones.
13:35Myth vs Fact: accuracy
Myth: higher accuracy always means a better model. Fact: with imbalanced classes, accuracy can reward doing nothing. Always look at the confusion matrix, and choose the metric that matches what each kind of mistake costs.
13:51Recap
Let's recap. The confusion matrix splits predictions into true positives, false positives, false negatives and true negatives. Precision asks whether our alarms are right; recall asks whether we caught everyone. F1 balances the two. The ROC curve shows every threshold at once, and the A-U-C is the chance the model ranks a positive above a negative. And the threshold itself should come from the costs of each mistake. One sentence to remember: precision asks "are my alarms right?", and recall asks "did I catch them all?"
14:30Next: k-NN and Naive Bayes
Mission complete. Is ninety-two point five percent good? Better than doing nothing, yes, but the real story is sixty percent precision and seventy-five percent recall. And with coupon costs in mind, Sana should use a much lower threshold. Next, two completely different ways to classify. One just asks, "Who are your neighbours?" The other uses Bayes' theorem to read reviews and catch spam. That's k nearest neighbours and Naive Bayes. See you on the map.