Algorithmic bias research · Open source
AI systems decide your freedom, your job, your future. This project proves the bias is measurable - and shows exactly how to remove it.
Fair Code is a research and engineering project that exposes bias in real-world AI systems and demonstrates concrete mitigation strategies. Both projects follow the same structure.
Train a biased model. Measure the fairness gap. Engineer a fair model. Measure again. No theory. Just data, code, and results.
The bias in these systems is documented, measurable, and fixable. Removing a protected attribute isn't enough. Proxy variables carry the same signal through. Both must go.
yakew7/Fair-CodeEvery project in this repo follows the same bias detection and mitigation workflow. Reproducible. Transparent. Measurable.
Real-world data with demographic signals: ProPublica COMPAS, Kaggle recruitment datasets.
Include protected attributes (race, gender, age) alongside predictive features.
Calculate positive prediction rate differences across demographic groups. Each gap ships with a 95% bootstrap confidence interval and a permutation-test p-value, so a real disparity can be told apart from sampling noise.
Drop protected attributes and correlated proxy variables that smuggle bias back in.
Fair model trained on merit features only. Gap measured again. Results compared.
A real algorithm used in US courtrooms. ProPublica's public dataset, 70,000+ records. The bias is not a glitch. It's baked in.
Removing race alone isn't enough. Custody Status is a proxy variable. It carries the racial signal through the model even when the race column is dropped. Both features had to go.
Women hired 20.9% less than equally qualified men. The algorithm wasn't told to discriminate. It learned to.
Dropping gender and age, retaining only Experience Years and Technical Test Score, collapsed the fairness gap from 4.51% to 0.12%. Merit features alone produce near-perfect demographic parity.
A lending model rates young applicants as bad credit risks at 6+ points higher than older applicants with identical financial profiles. It learned age from job tenure.
Employment tenure looks like a legitimate financial signal - and it is. But it's also a near-perfect proxy for age. A 24-year-old cannot have 10 years of employment history. The model penalizing short tenure was partially penalizing youth. Dropping both age and employment forced it to evaluate what a borrower has - savings, credit history, loan purpose - rather than how long they've been alive. A caveat the new significance testing makes explicit: on a 200-row test set this 7.16% gap is not statistically significant (p = 0.26, CI spans zero) - a reminder that small samples demand a confidence interval before a point estimate is read as proof.
An insurance AI flags older patients for high-cost claims at 7.93 points higher than younger patients. BMI, smoking status, and diabetes status encode race without naming it.
BMI, smoking status, and diabetes diagnosis rates all differ significantly by race and class - so a model trained on them learns to discriminate by race without the word ever appearing. These are the CustodyStatus of health insurance: clinical-sounding features that carry protected-class signal because of structural inequalities baked into American healthcare. Dropping them alongside age and gender reduced the age gap by 60% and the gender gap by 72%. Honest caveat, now that every gap carries a p-value: on this small test set neither the age nor the gender gap is statistically significant (both p > 0.2, CIs span zero), so these numbers show the mechanism and direction of the bias rather than a proven effect size - exactly the distinction the confidence intervals exist to enforce.
An automated means-test flags male applicants as ineligible at 18 points higher than female applicants - not because of what they earn, but because of who they're married to.
Automated benefits systems don't need to name sex or race to discriminate by them. relationship (Husband/Wife), marital.status, hours.per.week, and occupation are the CustodyStatus of welfare AI - features that sound purely economic but carry protected-class signal because of how work, caregiving, and labour markets are structurally organised. Dropping all four alongside the direct protected attributes reduced the sex gap by 53%, the race gap by 46%, and the national-origin gap by 88%.
A hospital readmission model flags patients for high clinical risk using payer code and discharge destination - variables that measure insurance access, not medical severity.
Healthcare readmission models don't need race or gender to discriminate by them. payer_code, discharge_disposition_id, medical_specialty, and number_inpatient are the CustodyStatus of clinical AI - features that look like neutral operational data but encode structural inequalities in insurance, geography, and access to preventive care. The age gap reduced 68% and the race gap 25%. With significance testing added, the picture sharpens: on this large dataset only the age gap clears significance (p < 0.05, CI above zero) in both models, while the gender and race gaps sit within sampling noise (p > 0.3, CIs crossing zero) - so the age reduction is the one effect the numbers actually support. The gender gap moved from −0.02% to 0.04% - a shift well inside the noise band, not a real widening. The causal direction matters: lower SNF access creates readmission risk. The patient does not bring the risk to the gap - the gap creates the risk.
A tenant-screening company buys a criminal-history risk score and hands the landlord a high-risk flag on the applicant - a flag that fires 7 points more often for Black applicants than white ones, before the landlord reads a word of the application.
Removing Race from a tenant-screening model does almost nothing, because the score is built out of criminal-history counts - and those counts are not a race-neutral measure of risk. Prior arrest and conviction episodes measure how often the system has stopped, charged, and convicted a person, and over-policing means Black applicants carry more of them for the same behaviour. Every one of the twelve proxies differs by race at p far below 0.05, with prior violent-arrest and gun-charge history the strongest, and Residence_Changes standing in for the eviction history real screeners buy. Dropping race and all twelve proxies only cuts the gap from 7.17% to 5.07% (a 29% reduction), and it stays significant (p=0.0007) - because the residual bias lives in the label itself. The model is trained to predict re-arrest, and re-arrest is a policed quantity. When the target is downstream of the same enforcement that produced the proxies, no feature removal fully closes the gap - the real remedy is questioning whether a re-arrest-derived score belongs in a housing decision at all.
The audits above measure bias in a model. The Profiler works upstream: drop in any CSV and get an instant demographic representation audit - missing subgroups, skewed age/sex distributions, geographic under-sampling.
🔒Runs entirely in your browser - your file never leaves your machine.
The seven audits above each run a bespoke unfair.py /
fair.py pair. The benchmark harness applies one uniform
pipeline to all seven instead: five mitigation strategies - baseline, drop-the-protected-attribute,
drop-protected-plus-proxies, Fairlearn ExponentiatedGradient
in-processing, and Fairlearn ThresholdOptimizer post-processing -
each run across three model families and scored on six fairness metrics with a bootstrap
confidence interval and a permutation-test p-value. On COMPAS the demographic parity gap goes
86% → 18% → 12% → 1.4% → 2.4% across the five strategies - the two strongest, constraint-based
tools land within a point of the simple proxy-removal fix, which is the basis for calling that
residual gap a floor rather than a limitation of any one method.
📊Contributor-facing: add an audit.yaml manifest, the harness runs the rest. Results and figures committed to results/.
Each card opens a focused explainer page. The homepage stays light, the long-form write-ups stay on site, and the source markdown lives in the repo.
of companies use AI to screen job applicants before a human sees a resume (Forbes, 2024)
US states have used algorithmic risk tools in criminal sentencing
federal laws currently require hiring AIs to be audited for gender or racial bias
Algorithms like COMPAS are deployed in courtrooms right now. Hiring AIs filter your resume before a human ever reads it. The bias in these systems is documented, measurable, and fixable.
More datasets, more domains, more bias exposed and fixed. Follow the project on Instagram for updates.
The short version of what this project is, what it isn't, and how to reach a human about it.
An open-source research project that audits real-world AI systems for demographic bias, then engineers a fixed version of the same model and measures the gap before and after. Every audit follows the same pipeline: train a biased model, measure the fairness gap, remove protected attributes and proxy variables, retrain, and measure again.
No. Fair Code is a research and engineering project, not legal or regulatory advice. The audits demonstrate that bias is measurable and fixable in a research setting - they are not a substitute for a formal compliance review, and no results here should be relied on as legal counsel for a production system.
Demographic Parity is the primary constraint used to mitigate bias, alongside six fairness metrics used to measure it. See the Methodology section and the Fairness Metric Conflicts explainer for why no single metric captures fairness completely, and why the choice of metric is itself a judgment call.
No. The Open Dataset Profiler runs entirely client-side in your browser - your CSV is parsed and analyzed locally and is never uploaded to a server.
Yes - contributions are welcome. See CONTRIBUTING.md on GitHub. Note that the benchmark results are currently frozen for a paper in peer review, so new audits are staged on a branch and merged into main after publication rather than being blocked outright.
MIT. See the LICENSE file - the code, audits, and explainers are free to use, modify, and redistribute with attribution.
Email yashkewlani2020@gmail.com for questions, bug reports, or collaboration - or open an issue on GitHub.