Zero Labs
Industry News / AI

My Model Was 87% Accurate and Almost Perfectly Calibrated.

Source · Towards AI By EMMANUEL NWANGUMA

From the publisher’s feed, collected in the ZeroLabs newsroom.

My Model Was 87% Accurate and Almost Perfectly Calibrated. It Still Selected Men at Three Times the Rate of Women.An audit toolkit, the result it produced, and the four bugs that would have made it wrong.Most machine learning portfolios show a model being built. Very few show a model being audited, and auditing is the step that decides whether a model ships.So I built model-audit. You hand it a fitted scikit-learn, XGBoost or PyTorch model, and it gives you back:Global explanations: which features move the model, and by how much (SHAP).Local explanations: why it made one specific decision.Anchors: simple rules that pin a prediction in place.Counterfactuals: the smallest change a person could make to get a different outcome.A fairness audit: demographic parity, disparate impact, equalized odds and a calibration gap for every protected attribute, with every group’s sample size printed beside its rate.A model card in JSON, Markdown and PDF.Every method except SHAP is written by hand, in code short enough to read. A fairness tool whose definitions you cannot inspect is not an audit tool. It is a second black box.Then I pointed it at a model.The live demo at model-audit.streamlit.app.The model looked goodThe model is a gradient-boosted classifier trained on the UCI Adult census extract: 48,842 people, predicting whether income is above $50K. I scored it on a held-out quarter, 12,211 rows.An expected calibration error of 0.007 means that when this model says “70%”, it is right about 70% of the time. By the measures most teams check, this model is finished.The audit said otherwiseFive of eight checks fail. The model predicts “>$50K” for 25.6% of men (n = 8,147) and 8.4% of women (n = 4,064). That is a selection ratio of 0.33. The “four-fifths” convention from US employment guidance flags anything below 0.80.The explanations agree. Ranked by mean absolute SHAP value, sex=Female is the 6th most important of 91 features. It sits above capital loss and above every occupation. The model is not working out sex from proxies. It is using the column.The part most fairness posts skipHere is where the story gets more honest, and more useful.For sex, demographic parity fails but equalized odds passes. Those two checks ask different questions:Demographic parity asks whether both groups are selected at the same rate.Equalized odds asks whether the model is equally right for both groups: the same true positive rate and the same false positive rate.The model can fail the first and pass the second because the groups differ in the data itself. In this 1994 extract, 11.0% of women and 30.4% of men earn above $50K. A perfectly accurate model would still select men at almost three times the rate.So how much of the gap does the model create? I compared the model’s selection ratio with the ratio already in the data:In the data: 0.110 / 0.304 = 0.362In the model’s predictions: 0.084 / 0.256 = 0.327So the model did not invent the gap. But it falls further short for women than for men. For every 100 men who really earned above $50K, it picked about 84 men. For every 100 such women, it picked about 76. In relative terms, women’s share of the picks shrinks. Then there is the error that hurts most. Among women who really did earn above $50K, the model found 59.6%. Among men, it found 66.0%. Qualified women are missed more often.This is the real point of the project. “Is this model fair?” has no single answer, because different definitions of fairness cannot all hold at once when groups have different base rates. That is a known result, not a flaw in this model. An audit’s job is not to hand down a verdict. It is to put every definition on the table with its numbers, so the people deciding can see which trade-off they are making.What I learned building itAccuracy and calibration say nothing about fairness. This model is excellent on both and still fails five checks.Every rate needs its n beside it. The smallest race group in the test set has 103 people. A gap measured on 103 people is a reason to look closer, not a finding to publish. The tool prints n for every group and marks any attribute with a group below 30 as unreliable.Counterfactuals have to be actionable. Telling someone to change their age or race is not advice. Immutable features are never touched, and if no allowed change flips the prediction, the tool says so rather than inventing a “closest attempt”.Explanations describe the model, not the world. “Changing education to a Masters flips the prediction” does not mean education causes income.What brokeAll four of these happened after every test had passed. I found them by running the full audit and reading what it said.The counterfactuals told everyone to earn $99,999 in capital gains. Candidate values came from each column’s 0th, 25th, 50th, 75th and 100th percentiles. Capital gain is zero up to the 75th percentile, so the only alternative the search ever tried was the maximum: 99,999. In this dataset that number is a cap code, not a real income. Every rejected applicant got the same “advice”. The candidate grid now runs from the 1st to the 99th percentile, and a test makes sure a capped extreme can never be suggested again.2. The fix exposed a second problem. With the cap gone, every row got the same advice: “have $15,024 of capital gains.” That is true for the model and useless to a person, because capital gain measures wealth, not a choice. With capital gain and loss treated as non-actionable, the search proposes changes to education, hours, occupation and sector. For rows it cannot honestly flip, it returns nothing: 17 of the first 40 rejected rows got a real counterfactual.3. The importance chart was in alphabetical order. The bar chart sorted features alphabetically, so the “top features” chart showed age first and sex=Female last. A ranking chart that is not ranked tells the reader the wrong thing. You only see that by looking at the page.4. The demo disagreed with the README. It defaulted to a 12,000-row sample for speed. That shrank the smallest race group to 26 people and moved race equalized odds from 0.135 to 0.647. The interface did warn about it, but only on one tab. The demo now runs on the full dataset by default, and every check shows its smallest group’s n.There was a fifth, smaller one. Three tests passed on my machine and failed on GitHub, because my environment already had two optional dependencies installed that CI did not. A green local run is a claim about your machine, not about the code.Caveats, stated plainlyAdult is a 1994 census extract. $50K is a 1994 threshold, and the base rates are not today’s.The fairness metrics are descriptive. They measure gaps in this dataset. They do not establish that a model is unlawful, and they do not prove discrimination.The thresholds (0.10 and 0.80) are conventions from fairness tooling and US employment guidance, not laws. They are parameters, and the report prints the ones used.The tool measures gaps. It does not fix them. Reweighting, threshold adjustment and constrained training are separate work.Try itCode: github.com/Emart29/model-audit, MIT licensed, 39 tests.Live demo: model-audit.streamlit.appRun the whole audit locally with python -m model_audit demo. It reproduces every number in this article.The next project in this series moves from auditing a classical model to the layer that decides whether an LLM change ships: an eval harness that catches regressions before users do.I’m Emmanuel Nwanguma, an ML and AI engineer in Lagos. View My PortfolioMy Model Was 87% Accurate and Almost Perfectly Calibrated. was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.