Logistic regression
A squashed weighted sum becomes a probability
The sigmoid turns a score into 0 to 1; a threshold makes it a class.
For a yes or no answer, take the same weighted sum and pass it through an S-shaped curve, the sigmoid. Whatever goes in, what comes out lies between zero and one, so it reads as a probability. Here, the chance of passing an exam by hours studied. Where the curve crosses one half is the decision boundary. Despite its name, logistic regression is a classifier, and usually the first one to try.
Log loss · Going deeper
A confident wrong answer costs far more than a hesitant one
Log loss is −ln of the probability given to the true class, averaged.
Confusion matrix
Every prediction lands in one of four cells
True positive, false negative, false positive, true negative.
To judge a classifier, count its answers. Here is a fraud model checked against ten thousand card payments, one hundred of which were fraud. Eighty frauds were caught: true positives. Twenty frauds slipped through: false negatives. Two hundred honest payments were blocked: false positives. And nine thousand seven hundred honest payments went through: true negatives. Every metric on the next pages comes from these four numbers.
Multi-class metrics · Going deeper
Three classes: one matrix, three scores each, and a choice of average
Macro averages classes equally; weighted by size; micro equals accuracy.
Accuracy
Accuracy hides the rare class: doing nothing scores higher
On rare classes, accuracy rewards the model that never says yes.
Accuracy is the share of answers that were right. Our model scores ninety seven point eight percent. Now a model that does nothing, that calls every payment fine, scores ninety nine percent. It is more accurate and it catches no fraud at all. Whenever one class is rare, accuracy is the wrong question.
Precision and recall
Precision: were the alarms real? Recall: were the cases caught?
Precision = TP ÷ all flagged. Recall = TP ÷ all real cases. F1 balances them.
Two better questions. Precision: of the two hundred and eighty payments we flagged, how many were fraud? Eighty. Under thirty percent. Recall: of the hundred frauds, how many did we catch? Eighty percent. F1 combines them as a harmonic mean, which stays low if either one is low. Which matters more depends on which mistake costs more.
Decision threshold
Moving the threshold trades precision against recall
Lower the threshold: more caught, more false alarms. Raise it: the reverse.
A classifier does not really answer yes or no. It gives a score between zero and one, and a threshold turns that into a decision. The grey bars are honest cases, the purple bars are positives. They overlap. Wherever you draw the line, some of each fall on the wrong side. Move the threshold down, and recall rises while precision falls. Move it up, and the opposite. Same model, different business choice.
Decision threshold · Going deeper · 1 of 2
The ROC curve shows every threshold; AUC sums it up
AUC 1.0 is perfect, 0.5 is guessing. It compares models before a threshold is chosen.
The ROC curve draws every threshold at once. Each point plots how many positives are caught against how many negatives are falsely flagged. The diagonal is a coin toss. The higher the curve bows towards the top left corner, the better the model. The area under it, the AUC, has a plain meaning: pick one positive and one negative at random, and it is the chance the model scores the positive higher.
Choosing the threshold · Going deeper · 2 of 2
Price each mistake, and one threshold is cheapest
Pick the threshold that minimises misses × their cost + false alarms × theirs.
Lesson complete
You finished “Classification”
Nicely done.