Judging a Classifier
A model can make different kinds of mistake, and they may have very different consequences. Counting correct answers alone can hide the errors that matter most for the task.
16 sections · 15 questions · 4 coding challenges
The arrow keys move between sections too.
What Does It Cost to Raise a False Alarm?
BOTIE
Tanner and Swets studied visual detection in 1954 using a decision-making account. Their work belongs to the development of signal detection theory, which separates the evidence available to an observer from the criterion used to make a decision. A change in willingness to say yes need not mean that the observer can distinguish the signals any better.
A classifier faces the same distinction. It produces scores, and a threshold turns them into decisions. Counting correct answers alone hides which mistakes changed when we moved that threshold. We therefore keep true detections, missed cases, and false alarms separate before deciding which tradeoff suits the problem.
Sources for this history
Two Models Can Be Equally Accurate and Fail Differently
A review system can miss a case needing attention or send an unnecessary alert. These are different mistakes. One percentage of correct answers does not tell us which mistake the system makes.
First sort predictions by what happened. Then choose a measurement that answers the question we care about.
Keep the prediction beside the answer
For one observation, record both the predicted decision and the known answer. Neither alone tells us whether the decision was useful. Together they identify the outcome.
Prediction
- Flag for review
Known answer
- Review was needed
Count the outcomes before naming the metric
Precision, recall, specificity, and accuracy each summarize a particular part of the same basic evidence. Their formulas become readable once the question behind each fraction is clear.
The full classifier supplies actual predictions to count. Its threshold can change while its underlying scores remain fixed.
Explore the full example
Look at the false positives and false negatives separately. Move the threshold and watch which kind of mistake becomes more common.
called adult, is adult … | called child, is adult … |
called adult, is child … | called child, is child … |
Part 1. One Number Is Not a Judgement
1. Twelve people, and two the boundary cannot place
Twelve people are in the box above, six children and six adults measured by height and weight, and each is labelled with the chance the fitted model gives them of being an adult. Ten of them are easy. Two are not, since there is a child at 168 centimetres and 66 kilograms, and an adult at 150 centimetres and 50 kilograms. Their measurements overlap the other class, and this fitted model gives the child a higher adult score than the adult. A single threshold on those scores cannot classify both correctly.
The model gives the tall child a chance of 0.8669 and the short adult a chance of 0.4911, and with the dial at the halfway mark it calls the first an adult and the second a child. Accuracy reports 0.8333 and stops. The colours in the box say more, that one child was called an adult and one adult was called a child, and those are different mistakes that a reader may care about very differently.
Different applications can attach different costs to these two mistakes. This height-and-weight exercise illustrates that distinction; it does not establish a reliable way to determine somebody’s age.
Keep in mind
2. Accuracy on a crowd where adults are rare
On the twelve the two classes are balanced, so accuracy is merely coarse. Where one class is rare it is misleading. Take thirty people of whom four are adults, two of them child-sized, and consider the laziest classifier there is, which calls everybody a child. It finds no adult at all and it is right about twenty-six people in thirty.
…
The lazy classifier scores 0.8667, which is one minus the share of adults, and it would score 0.99 on a crowd where one person in a hundred was an adult. The fitted boundary at the halfway threshold scores 0.9333, finds three of the four adults and wrongly calls one child. The same boundary at a threshold of 0.7 also scores 0.9333, finds two of the four and wrongly calls nobody.
Two classifiers with the identical accuracy, one of which finds half again as many adults as the other, and a third that finds none and is right about two people fewer.
everybody a child 26 right of 30 = 0.8667 adults found 0 of 4
the boundary at 0.5 28 right of 30 = 0.9333 adults found 3 of 4, one child wrongly called
the boundary at 0.7 28 right of 30 = 0.9333 adults found 2 of 4, no child wrongly calledKeep in mind
3. The four cells
What replaces the one number is a table of four. Every person is either an adult or a child, and the model either called them an adult or did not, so each person falls into exactly one of four cells according to what was true and what was said. Two of the cells are the model being right and two are the model being wrong in the two different ways.
is adult is child
called adult true positive false positive
called child false negative true negativeThe twelve at the halfway threshold
Six adults, of whom five clear the threshold and one, the short one at 0.4911, does not. Six children, of whom five fall below it and one, the tall one at 0.8669, does not. Every rate on this page is a ratio of these four numbers.
true positives 5 false negatives 1
false positives 1 true negatives 5The words are a convention worth fixing once. Positive means the class the question is about, adult here, and has nothing to do with good news. A false positive is a child called an adult and a false negative is an adult called a child, so the first word says whether the call was right and the second says what the call was.
Keep in mind
Part 2. Two Questions Asked of One Table
4. Precision reads along the row of calls
Suppose the model has just called somebody an adult. How much should we believe it? That question only concerns the people it called adult, which is the top row of the table, and asks what share of that row is on the diagonal. On the twelve the model called six people adult and five of them were.
precision = true positives / (true positives + false positives)
= 5 / (5 + 1) = 0.8333…
Precision is the rate to watch when a false alarm is what costs. A test that sends every flagged person for an expensive second examination wants the flags to be right, and it can raise its precision by flagging fewer people, which is exactly the move the next question punishes.
Keep in mind
5. Recall reads down the column of adults
Now ask the other question. Of the adults in the crowd, how many did the model find? That concerns only the people who really are adults, which is the left column of the table, and again asks what share is on the diagonal. There are six adults and the model found five.
recall = true positives / (true positives + false negatives)
= 5 / (5 + 1) = 0.8333The two rates share a numerator and differ in what sits underneath, and switching the buttons above between precision and recall shows the highlighted cells turning from the row to the column. On the twelve they come out equal, which is a convenience of this crowd rather than a rule, since there happen to be six of each class and one miss in each direction. On the rare crowd at the halfway threshold they also happen to agree, at 0.75, and at a threshold of 0.7 they part to 1.0 and 0.5.
Recall is the rate to watch when a miss is what costs. A screening test wants to find every case and will accept false alarms to do it, and it can raise its recall by calling more people, which is the move precision punishes. The two are the same table read in two directions, and which one a field quotes first says mostly which mistake that field is more afraid of.
Keep in mind
6. Specificity, and the false positive rate
Nothing so far has looked at the children except to count the wrongly called ones. Specificity is recall for the other class, the share of the children the model left alone, and it reads down the right column. Its complement, the share of children the model wrongly called adult, is the false positive rate, which is the horizontal axis of the curve in Part 3.
| the rate | the question it answers, and its value on the twelve at 0.5 |
|---|---|
| accuracy (TP + TN) / everybody | of everybody, how many were called rightly? 10 of 12, 0.8333. |
| precision TP / (TP + FP) | of the people called adult, how many are? 5 of 6, 0.8333. |
| recall TP / (TP + FN) | of the adults, how many were found? 5 of 6, 0.8333. |
| specificity TN / (TN + FP) | of the children, how many were left alone? 5 of 6, 0.8333. |
| false positive rate FP / (TN + FP) | of the children, how many were wrongly called? 1 of 6, 0.1667, which is one minus the specificity. |
On the rare crowd the difference between the two columns is plain. The boundary at 0.5 has a specificity of 0.9615, because twenty-five of twenty-six children were left alone, and a recall of 0.75, because three of four adults were found. Both are read off the same table, and a report that quoted only the first would be describing how well the model does on the class it was not asked about.
Keep in mind
7. A ratio with nothing underneath it
Each of these rates is a count over a count, and a count can be zero. Turn the dial in the box above to 0.99, higher than any chance in the crowd, and the model calls nobody an adult. Its precision is then zero over zero. That is not a precision of zero, since a model that made no positive claims has not made a wrong one, and the difference is kept by refusing to return a number rather than by returning 0.
precision at 0.99 = 0 / (0 + 0) undefined, nobody was called adult
recall on a fold with no adults = 0 / (0 + 0) undefined, there was nobody to find
F1 with precision 0 and recall 0 = 2 · 0 · 0 / (0 + 0) undefinedRecall has the same gap when there are no adults to find, which no threshold can cause on a fixed crowd and which a held-out fold of a small crowd causes easily, as Part 7 shows. Accuracy has a denominator whenever there is anybody at all, and specificity whenever there is a child. A tool that quietly substitutes zero for any of these turns a fact about the data into a poor score for the model, and every rate on this page comes back as undefined where its denominator is empty.
Keep in mind
Check yourself
Questions on Parts 1 and 2
Question 1 of 5
On the rare crowd of thirty the classifier that calls everybody a child scores 0.8667, which is one minus the share of adults.
Part 3. The Threshold Trades One Mistake for the Other
8. A chance is not a verdict
The model in the box does not say adult or child. It says 0.4911, and somebody has to decide what to do with that. The logistic regression page introduced the threshold as the number a chance is compared against, and this page treats it as a dial, because the boundary and every chance were computed once and the dial only moves the line between the two calls. Nothing refits when it turns, and the four cells change only because people cross the line.
…
Drag the marker down to 0.3. The short adult’s 0.4911 now clears the bar, so all six adults are found and recall is 1.0, while the tall child’s 0.8669 still clears it too, so seven people are called adult and six of them are, for a precision of 0.8571. Drag it up to 0.9 and only the three adults above 0.9 are called, so precision is a perfect 1.0 and recall halves to 0.5, with the adults at 0.7376, 0.7684 and 0.4911 now called children.
The model did not change between the two readings, and neither did any chance; the line the calls are read against did.
Keep in mind
9. Recall can only fall as the threshold rises, and precision need not
Raising the threshold can only turn a call of adult into a call of child, never the reverse, so the true positives can only fall and the false negatives can only rise. Recall is the true positives over the number of adults, and the number of adults does not depend on the threshold at all, so recall is a falling count over a constant and cannot rise. That is why the indigo curve above only ever steps downward.
threshold up ⇒ TP can only fall, FN can only rise
recall = TP / (TP + FN) where TP + FN is the number of adults, fixed
so recall never rises as the threshold risesPrecision has no such guarantee, because both its numerator and its denominator move. Reading the amber curve at five thresholds on the twelve gives 0.75 at 0.1, 0.8571 at 0.2, 0.8333 at 0.5, 0.75 at 0.8 and 1.0 at 0.9. It rose, fell, fell and rose, and each move is one person crossing the line.
Between 0.2 and 0.49 the seven people above the line include the tall child and every adult; at 0.5 the short adult drops out, taking one true positive from a numerator of six and one person from a denominator of seven, and the ratio falls from six sevenths to five sixths.
| threshold | called adult | of whom adults | precision | recall |
|---|---|---|---|---|
| 0.1 | 8 | 6 | 0.7500 | 1.0000 |
| 0.2 | 7 | 6 | 0.8571 | 1.0000 |
| 0.5 | 6 | 5 | 0.8333 | 0.8333 |
| 0.8 | 4 | 3 | 0.7500 | 0.5000 |
| 0.9 | 3 | 3 | 1.0000 | 0.5000 |
Five readings of the sweep on the twelve. Recall steps down and never up; precision moves both ways.
Keep in mind
10. The precision-recall curve, and the area under its steps
Put the two rates against each other rather than against the threshold, and the threshold becomes a position along the curve. Start with it above the highest chance, where nobody is called, and lower it through each person’s chance in turn. Every step adds one person to those called adult. If they were an adult, recall moves right; if they were a child, precision drops. Nothing else can happen, so the curve is a staircase, and it is drawn as one.
…
On the twelve there are twelve distinct chances and so twelve corners. The first three steps add the three most confident adults and precision holds at 1.0 while recall climbs to 0.5; the fourth adds the tall child and precision drops to 0.75 with recall unmoved; three more adults take recall to 1.0 with precision recovering to 0.8571; and the last five steps add the remaining children, lowering precision to 0.5 while recall has nowhere left to go.
The area under the steps is the average precision, 0.9151 here, and the rightmost precision is always the share of the crowd that is adult, since calling everybody adult finds every adult and is right about a prevalence’s worth of them.
average precision = Σ (recall gained at the corner) × (precision at the corner)
= (1/6)·1 + (1/6)·1 + (1/6)·1 + 0·0.75 + (1/6)·0.8 + (1/6)·0.8333 + (1/6)·0.8571 + 0 + …
= 0.9151Keep in mind
11. The receiver operating characteristic, and a count of pairs
The other picture swaps precision for the false positive rate and puts recall up the vertical axis. It starts at the origin, where nobody is called and neither rate has anything in its numerator, and ends at the top right, where everybody is called. Lowering the threshold through an adult moves it up by one sixth, and through a child moves it right by one sixth, so a model whose chances rank every adult above every child climbs the whole left edge before crossing the top.
…
The area under the curve has a meaning that can be counted rather than integrated. Pair each adult with each child, thirty-six pairs on the twelve, and ask in how many the adult’s chance is the higher. The tall child at 0.8669 outranks three adults, the short one at 0.4911 and two more at 0.7376 and 0.7684, and every other pair is in the right order, so thirty-three of thirty-six are, and the area is 0.9167. A coin would draw the diagonal and score 0.5.
area under the ROC = share of (adult, child) pairs with the adult ranked higher, a tie counting a half
= 33 / 36 = 0.9167 on the twelve
= 102 / 104 = 0.9808 on the rare crowdKeep in mind
12. What the two pictures answer differently
The two curves are built from the same sweep and disagree about what a good model looks like when one class is rare, because one of them reads a column of the table and the other reads a row. Recall and the false positive rate are each a share of one class, so the ROC does not know how many of each class there are, and its diagonal is a coin’s curve on any crowd.
Precision is a share of the people called adult, who are drawn from both classes, so the precision-recall curve knows the prevalence intimately and ends at it.
| crowd | share adult | area under the ROC | a coin’s ROC area | average precision | a coin’s average precision |
|---|---|---|---|---|---|
| the twelve | 0.5000 | 0.9167 | 0.5 | 0.9151 | 0.5000 |
| adults rare | 0.1333 | 0.9808 | 0.5 | 0.9167 | 0.1333 |
Both crowds through the same sweep. A coin’s area under the ROC is 0.5 on any crowd; a coin’s average precision is the share of the crowd that is adult.
On the rare crowd the model’s average precision is 0.9167 against a floor of 0.1333, where on the twelve it is 0.9151 against a floor of 0.5, so the rare crowd’s figure is the larger achievement though the two numbers are within 0.002 of each other. The ROC area reads 0.9808 and 0.9167 against the same floor of 0.5 on both.
When the positive class is rare and the false alarms are what will be looked at, the precision-recall picture is the one that shows what it will cost, since a false positive rate of 0.04 on the rare crowd is one child, and on a crowd of ten thousand children it would be four hundred people to be examined for every few adults found.
Keep in mind
Part 4. One Number, When One Is Needed
13. The harmonic mean
Sometimes two rates have to become one, to rank candidate models or to put a figure in a report. The obvious way is to average them, and it is wrong in a specific way. At a threshold of 0.9 the twelve give a precision of 1.0 and a recall of 0.5, and the arithmetic mean of those is 0.75, which is a respectable-looking score for a model that missed half the adults. The harmonic mean is 0.6667, and it is lower because the harmonic mean is pulled towards whichever rate is worse.
F1 = 2 · precision · recall / (precision + recall)
at 0.9 on the twelve: 2 · 1.0 · 0.5 / (1.0 + 0.5) = 0.6667 the arithmetic mean would say 0.75
at 0.5 on the twelve: 2 · 0.8333 · 0.8333 / 1.6667 = 0.8333 the two agree, so any mean of them is 0.8333›Why the harmonic mean cannot be gamed
Send recall to zero while keeping precision at 1.0, which a model does by calling one obvious adult and nobody else. The arithmetic mean reports 0.5, half marks for finding almost nothing. The harmonic mean reports 0, since the numerator carries the product of the two rates and a zero in either makes it zero.
The same holds the other way round, calling everybody adult for a recall of 1.0 and a precision equal to the prevalence, and the harmonic mean of 1.0 and 0.5 on the twelve is 0.6667 again. A model cannot buy a good F1 by abandoning one of the two rates entirely.
Keep in mind
14. Leaning the mean with beta
F1 weighs the two rates equally, and nothing says they should be. The general form carries a number beta that says how many times more recall matters than precision, and the usual pair of alternatives are a half, which leans towards precision, and two, which leans towards recall. At a half the recall is weighted a quarter as much in the denominator; at two it is weighted four times as much.
F_β = (1 + β²) · precision · recall / (β² · precision + recall)
at 0.9 on the twelve, precision 1.0 and recall 0.5:
F½ = 1.25 · 0.5 / (0.25 + 0.5) = 0.8333
F1 = 2 · 0.5 / (1 + 0.5) = 0.6667
F2 = 5 · 0.5 / (4 + 0.5) = 0.5556…
The three curves agree wherever precision and recall agree, which on the twelve is the whole stretch from 0.5 to 0.73 where both are 0.8333, and part company wherever the two rates do. At 0.9, where precision is perfect and recall is half, the precision-leaning score says 0.8333 and the recall-leaning one says 0.5556, and the reader who is choosing between them is choosing which mistake to forgive.
Keep in mind
15. Choosing a threshold by an F-score, on the rows it was fitted to
Once there is one number, the sweep can be searched for the threshold that maximises it, and the dashed lines in the chart above mark where each F-score peaks. On the twelve all three peak at 0.18, which is the lowest threshold in the long flat stretch from 0.18 to 0.49 where every adult is found and only the tall child is wrongly called, and the sweep reports the lowest tied threshold rather than choosing among equals. On the rare crowd the three part.
| crowd | F½ peaks at | value | F1 peaks at | value | F2 peaks at | value |
|---|---|---|---|---|---|---|
| the twelve | 0.18 | 0.8824 | 0.18 | 0.9231 | 0.18 | 0.9677 |
| adults rare | 0.51 | 0.9375 | 0.51 | 0.8571 | 0.14 | 0.9091 |
Where each F-score peaks over the sweep at every hundredth, the lowest threshold reported on a tie.
On the rare crowd the recall-leaning score sends the threshold down to 0.14, where all four adults are found and two children are wrongly called, and the other two hold it at 0.51, just above the one child the model gives a chance of 0.5072, where three adults are found and nobody is wrongly called. Those are two defensible deployments of one model, and beta is what chose between them.
What the chosen threshold is worth
Every threshold on this page was chosen on the rows the boundary was fitted to, and the peak of a curve read off the fitting rows is optimistic in the same way a training score is. The grid search page measures how much the best of many candidates flatters, and a threshold is a candidate like any other, so it should be chosen on held-out rows and reported on rows held out again, which is the nested procedure that page describes.
Keep in mind
Check yourself
Questions on Parts 3 and 4
Question 1 of 5
Raising the threshold can lower recall but never raise it.
Part 5. More Than Two Classes
16. The K by K table
With children, teenagers and adults there are three ways to be right and six ways to be wrong, and the table grows to three rows by three columns, the true class down the rows and the call across the columns. The diagonal is the right answers and every other cell names a particular confusion, this class taken for that one. The crowd below is the multiclass page’s thirteen with three people added who confuse the classes, a teenager built like an adult, an adult built like a teenager, and a tall child.
With everybody judged and the width stated, fourteen of the sixteen are on the diagonal, for an accuracy of 0.875. The two off it are the tall teenager, called an adult, and the short adult, called a teenager, and the tall child was placed correctly. Those two cells say something a two-class table cannot, that the model confuses teenagers with adults in both directions and never confuses either with a child.
Keep in mind
17. Each class has its own precision and recall
Precision and recall survive the move to three classes, and they stop being single numbers. Each class gets its own pair, read off its own row and column of the table exactly as in Part 2, with that class standing as the positive one and the other two together as the negative.
The teenager row and column
Six people are teenagers, five of them called teenagers and one called an adult, so recall for the teenager class is five sixths. Six people were called teenagers, five of them teenagers and one an adult, so precision for the class is also five sixths. For adults the figures are four of five each way, 0.8, and for children five of five.
teenager precision 5 / 6 = 0.8333 recall 5 / 6 = 0.8333 F1 0.8333
adult precision 4 / 5 = 0.8000 recall 4 / 5 = 0.8000 F1 0.8000
child precision 5 / 5 = 1.0000 recall 5 / 5 = 1.0000 F1 1.0000A model can be excellent on the common class and useless on the rare one, and that is exactly the fact a single number hides. The per-class figures are what a report should show when the classes are of different sizes or different importance, and they are one row of the table each.
Keep in mind
18. Macro and micro are two different questions
Three precisions can be collapsed to one in two ways, and they answer different questions. Averaging the three per-class figures, which is called the macro average, gives every class an equal vote however many people it holds. Pooling the counts first and dividing once, the micro average, gives every person an equal vote and lets the common classes dominate.
macro precision = (1.0000 + 0.8333 + 0.8000) / 3 = 0.8778
micro precision = (5 + 5 + 4) / (5 + 6 + 5) = 14 / 16 = 0.8750On this crowd the two are close, 0.8778 against 0.8750, because the classes are nearly the same size. The micro figure is worth a second look, because where every person gets exactly one call the pooled numerator is the diagonal and the pooled denominator is everybody, so micro precision, micro recall and accuracy are the same number, 0.875 here, reported under three names, and the widget shows all three so the reader can see that they agree.
Keep in mind
19. The width has to be stated
A three-class table needs to know it has three classes, and there are two ways it can find out. It can be told, or it can read the true classes of the rows it was handed and count. The second sounds harmless and is where a held-out fold goes wrong, because a fold of a small crowd can easily hold no adults, and a table that counts its classes from the rows then has no column for adults at all.
Switch the widget in section 16 to judge the crowd without its adults and untick the stated width.
| the judged rows, and whether the width is stated | what happens |
|---|---|
| everybody, width inferred | the true classes run 0, 1, 2 and the table is three by three; identical to stating it. |
| without the adults, width inferred | refused. The rows’ true classes run 0 and 1, so the inferred table has two columns, and the tall teenager is called class 2, which the table has no column for. |
| without the adults, width stated as three | accepted. The adult row is empty and the adult column holds the one wrongly called teenager, so adult precision is 0.0, adult recall is undefined, and the macro recall is undefined with it. |
| without the teenagers, width inferred | refused by name, since the true classes are 0 and 2 and leave a gap, which is nearly always a filtered crowd rather than a two-class problem. |
| everybody, width stated as two | refused, because the rows name a class 2 that a two-class table cannot hold. |
| everybody, width stated as four | accepted, with an empty fourth class whose recall is undefined. |
The quiet case is the one the refusal above narrowly avoids. I measured a version of this crowd without the short adult, where the model places the tall teenager correctly, so that no judged row was called adult, and the inferred table came back two by two with no adult column and every figure defined, a table that is silently the wrong shape.
Stating the width turns that into a three-by-three table with an empty row, whose recall is undefined and says so. So the width is stated up front and the rows are held to it, which is the rule the fold endpoint of Part 7 uses on every fold.
Keep in mind
Part 6. What a Chance Means
20. A 0.7 is not seven in ten unless measured
Everything so far has judged the calls, and a call throws away the chance it came from. The model said 0.7376 about one adult and 0.9546 about another, and if those numbers mean what they say then, among many people given a chance near 0.75, about three in four should turn out to be adults. Whether they do is a separate question from whether the calls were right, and it is answered by binning the chances and counting.
…
On the twelve the bin from 0.8 to 1.0 holds four people at a mean chance of 0.9230, and three of the four are adults, a share of 0.75 against a promise of 0.92, since the tall child is one of the four. The bin from 0.6 to 0.8 holds two people at a mean of 0.7530 and both are adults.
The bin from 0.4 to 0.6 holds one person, the short adult, and the bin from 0.2 to 0.4 holds nobody. Twelve people cannot fill five bins, so most of what the diagram says here is that twelve is too few, which is a fair thing for it to say.
Over everybody the model balances, with a mean chance of 0.5000 against an observed adult rate of 0.5, which a logistic fit with an intercept does on its fitting rows because the fit itself demands it. The balance in the large and the gaps in the bins are both true at once, and only the bins can see that the chances above 0.8 are too high.
Keep in mind
21. Two scores for a chance, and what each one adds
The diagram can be summarised in two numbers, and they measure different things. The expected calibration error takes each bin’s gap between its mean chance and its observed share, weights it by how many people the bin holds, and averages. The Brier score skips the bins and takes every person’s squared gap between their chance and their outcome, 1 for an adult and 0 for a child.
expected calibration error = Σ_bins (people in bin / everybody) · | mean chance − observed share |
Brier score = (1 / n) Σ_people (chance − outcome)²The two scores on the three crowds
| crowd | people | expected calibration error | Brier score | Brier score of guessing the prevalence |
|---|---|---|---|---|
| the twelve | 12 | 0.1672 | 0.0983 | 0.2500 |
| adults rare | 30 | 0.0580 | 0.0382 | 0.1156 |
| an ideal case | 19 | 0.0776 | 0.0414 | 0.2493 |
Every figure read on the fitting rows. The last column is what a model that gave everybody the crowd’s adult share as their chance would score, which is the prevalence times one minus itself.
On the twelve the calibration error is 0.1672, most of it the four confident people of whom one was a child, and the Brier score is 0.0983 against the 0.25 that guessing the prevalence for everybody would earn. The Brier score rewards a chance for being near the right end as well as for being honest, so a model can lower it by ranking better without becoming better calibrated, and a model can be perfectly calibrated and score badly by saying 0.5 about everybody on a balanced crowd.
Keep in mind
22. Ranking and calibration are separate qualities
The area under the ROC and the reliability diagram can disagree completely about one model, and the reason is in what each reads. The area counts pairs and asks only which of two chances is the higher. Squash every chance towards 0.5, or stretch every chance towards the ends, and as long as the order of the people is untouched the area is untouched, at 0.9167 on the twelve, while the diagram moves every dot.
›Why any order-preserving change leaves the area alone
The area is the share of adult-child pairs in which the adult’s chance exceeds the child’s. Apply any rising function to every chance, and a pair that was in order stays in order and a pair that was out of order stays out of order, so the count is unchanged. The reliability diagram reads the chances’ values and not their order, so the same change moves every bin’s mean and can move people between bins.
This is why the two are reported separately and why a model with a high area can still be untrustworthy when its 0.7 is read as seven in ten. The repair for that is a second, small fit that maps the model’s chances onto observed frequencies on held-out rows, which is not built here and which this page therefore only names. What it does provide is the diagram and the two scores, which say whether such a repair is needed.
Keep in mind
Part 7. Judging on Rows the Fit Never Saw
23. Every number so far is a training score
The twelve in the box are the twelve the boundary was fitted to, and so are the thirty and the sixteen. Every rate, both curves, every peak and every bin above is therefore a training score, and the held-out evaluation page is about why that flatters and how dealing the crowd into folds and judging each on the rows it was not fitted to repairs it. That argument is not repeated here. What this page adds is what happens when the thing being folded is a table rather than a single squared error.
Two things change. The standardising of heights and weights that the fit needs has to be learned inside each fold, so that a held-out person never lends their mean to the fit that judges them, and the widget below does that. And a fold of two or three people can hold no adults at all, which is the undefined recall of section 7 arriving in practice.
Keep in mind
24. Pool the folds’ tables
With the twelve dealt into folds and the boundary refitted inside each, there are two ways to combine the folds into one verdict. Average each fold’s accuracy, so each fold counts equally, or add the folds’ tables into one table and divide once, so each person counts equally. The widget deals the same twelve four ways and reports both.
| the deal | accuracies averaged | tables pooled | spread | folds missing a class |
|---|
The pooled column reads 0.8333 on every row, because every person is held out in exactly one fold whatever the deal, so adding the folds’ tables always rebuilds one table of the same twelve people. The averaged column does not. Dealt seven ways it says 0.8571, because twelve people do not divide into seven equal folds and averaging gives a fold of one the same vote as a fold of two, and dealt five ways with the classes balanced it says 0.8.
On the plain five-fold deal the two happen to agree to the last digit, which is arithmetic luck and not a rule.
What settles the question is the fold with no adults, which the plain five-fold deal produces. It holds two people, the refitted boundary wrongly calls one of them an adult, and its recall is zero found over zero present. Averaged, that fold has to contribute something and whatever is chosen is a convention. Pooled, it adds nothing to either side of the ratio, which is right, because a fold with no adults in it has no evidence about finding adults.
So a classifier’s folds are pooled, and a spread across folds is reported only for accuracy, which is defined on any fold with anybody in it and reads 0.5 here on every deal.
pooled ( Σ TPₖ ) / ( Σ (TPₖ + FNₖ) ) a fold with no adults adds 0 to both
averaged (1/k) Σ TPₖ / (TPₖ + FNₖ) a fold with no adults has no term to addKeep in mind
Part 8. Implementation and Failure Contracts
25. What a complete implementation specifies
A complete implementation of these judgements states which class is positive and what labels it accepts, whether the threshold comparison is at or above, what it does with a denominator of zero for each rate, whether its curves are read at every distinct score or at a fixed grid, whether the area under the precision-recall curve is a step sum or a trapezoid and whether a conventional first point is added, how ties in the scores are counted in the ROC area, which beta an F-score uses, whether a multiclass average is macro or micro and what it does when a class’s rate is undefined, whether the class width is stated or inferred, how many bins a reliability diagram uses and whether they are equal in width or in count, and whether folds are pooled or averaged.
The choices on this page are these. Adult is positive and the labels are 0 and 1; a person is called adult at or above the threshold; an empty denominator gives an undefined rate rather than zero; the sweep reads every hundredth and both curves read every distinct chance; the average precision is a step sum with no conventional first point; a tied pair counts a half; the three betas are a half, one and two; both multiclass averages are reported and the macro one is undefined if any class is; the width can be stated and is inferred otherwise; five equal-width bins; and folds are pooled, with a spread for accuracy alone.
26. The edges, each one run
Every row below was run, through this page where it can reach the case and directly on the model where it cannot.
| the edge | the behaviour |
|---|---|
| an empty crowd, or one person | refused before any fit, by the request’s bound of at least two people. |
| two people, one of each class | refused by the fit, which says that estimating three parameters needs at least three people. |
| one class only | refused by the fit by name, since a classifier needs both classes. The two-class table itself accepts a crowd of one class and refuses only the rate that has no denominator, recall on a crowd with no adults. |
| a constant column | refused by the standardiser before the fit, because a column with no spread cannot be scaled. |
| a non-finite measurement | refused at the boundary by the request, which bounds every measurement; handed directly to the table, a non-finite label is refused as not finite. |
| a label that is not 0 or 1, or a chance handed in as a label | refused by the two-class table by name, which says which value it found; a threshold has to be applied before anything reaches it. |
| labels and calls of different lengths | refused, naming both lengths. |
| nobody called adult, or no adult present, or precision and recall both zero | precision, recall and F1 respectively are undefined and refused by name; accuracy and the other rates are still returned. |
| a threshold of 0 or 1 | refused at construction, since the model’s threshold is bounded to the open interval and the request’s is too. |
| more folds than the endpoint allows | refused by the request above ten folds; ten folds of twelve people are accepted, and a fold of one person is scored. |
| unfitted use | refused with the model’s own not-fitted error, before any judging can begin. |
| a renamed, missing or reordered feature | a renamed or missing feature is refused, naming what was expected and what arrived; reordered features are matched by name and accepted. |
| a three-class table with the width inferred from one class, or from rows that leave a gap | refused by name in both cases, since there is nothing to discriminate between and a gap is nearly always a filtered crowd. |
| a stated width narrower than a class present | refused, naming the class outside the table. |
| a stated width wider than the classes present | accepted, with an empty class whose recall is undefined and whose emptiness makes every macro average undefined. |
| a rate asked of a class the table does not have | refused, naming the span the table covers. |
| a fit that does not converge | accepted and reported. The fit on the twelve ran its full 2000 passes without converging, which a separable crowd causes, and the page says so where it quotes the chances. |
Two of those are documented rather than defended. A fit that never converges is the logistic regression page’s complete-separation case, and this page reports the passes run and the flag rather than refusing, because the chances it produces are still a ranking even where their values have run away. And the reliability reading needs bins, and a different binning gives a different calibration error from the same chances, so that number is reported with its binning and the Brier score beside it.
Check yourself
Questions on Parts 5 to 7
Question 1 of 5
On the sixteen, micro precision, micro recall and accuracy are the same number, 0.875.
Try it with Botie
Build with Botie
Write and run Python