---
id: wiki-2026-0508-bias-correction-algorithm
title: Bias Correction Algorithm
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [편향 보정, fairness algorithm, debiasing, AIF360, equalized odds, demographic parity]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [fairness, bias, ml-ethics, aif360, fairlearn, reweighing, post-processing, in-processing]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: Python
  framework: AIF360 / Fairlearn / scikit-learn
---

# Bias Correction Algorithm

## 📌 한 줄 통찰
> **"매 data 의 bias = 매 model 의 discrimination"**. 매 protected attribute (race, sex, age) 의 statistical balance 의 enforce. 매 3 stage: pre / in / post-processing. 매 fairness ↔ accuracy 의 trade-off 의 unavoidable.

## 📖 핵심

### 매 fairness metric
| Metric | Definition |
|---|---|
| Demographic parity | 매 P(ŷ=1 \| group) 의 equal |
| Equalized odds | 매 TPR + FPR 의 equal across group |
| Equal opportunity | 매 TPR 의 equal |
| Calibration | 매 P(y=1 \| ŷ, group) 의 equal |
| Individual fairness | 매 similar 의 similar treatment |
| Counterfactual fairness | 매 protected attr 의 flip 의 prediction unchanged |

→ 매 metric 의 mutually exclusive (Kleinberg impossibility).

### 매 stage

#### 1. Pre-processing (data)
- **Reweighing**: 매 sample weight 의 group balance.
- **Disparate impact remover**: 매 feature transform.
- **Resampling**: 매 oversample / undersample.
- **Suppression**: 매 protected attr 의 drop (단순).
- **Synthetic data**: 매 minority 의 augment (SMOTE).

#### 2. In-processing (training)
- **Adversarial debiasing**: 매 main task + 매 protected predict 의 adversary.
- **Fairness constraint**: 매 loss 의 add.
- **Reductions**: 매 cost-sensitive learning 으로 reduce.
- **Prejudice remover**: 매 regularization.

#### 3. Post-processing (output)
- **Reject option**: 매 ambiguous 의 favor disadvantaged.
- **Calibrated equalized odds**: 매 threshold per group.
- **Equalized odds post-processing**: 매 randomize.

### 매 trade-off
- 매 fairness ↑ → 매 accuracy ↓ (대부분).
- 매 metric 의 choice 의 critical.
- 매 business / legal constraint 의 align.

### Landmark cases
- **COMPAS** (ProPublica 2016): 매 recidivism 의 racial bias.
- **Amazon hiring tool**: 매 women 의 penalize.
- **Apple Card**: 매 credit limit 의 sex bias.
- **Gender Shades** (Buolamwini): 매 face recognition 의 dark female 의 35% error.

### Tool
- **AIF360** (IBM): 매 70+ algorithm.
- **Fairlearn** (Microsoft): 매 reductions + dashboard.
- **What-If Tool** (Google): 매 visualization.
- **Aequitas**: 매 audit.

### 매 EU AI Act 의 의무
- 매 high-risk system 의 bias monitoring.
- 매 audit log.
- 매 transparent disclosure.

## 💻 패턴

### Reweighing (AIF360)
```python
from aif360.datasets import BinaryLabelDataset
from aif360.algorithms.preprocessing import Reweighing

ds = BinaryLabelDataset(
    df=df,
    label_names=['target'],
    protected_attribute_names=['sex'],
)

rw = Reweighing(
    unprivileged_groups=[{'sex': 0}],
    privileged_groups=[{'sex': 1}],
)
ds_transformed = rw.fit_transform(ds)
# 매 sample weight 의 inject — 매 model 의 weighted loss.
```

### Adversarial debiasing (in-processing)
```python
from aif360.algorithms.inprocessing import AdversarialDebiasing
import tensorflow.compat.v1 as tf

sess = tf.Session()
debiased = AdversarialDebiasing(
    privileged_groups=[{'sex': 1}],
    unprivileged_groups=[{'sex': 0}],
    scope_name='debias',
    sess=sess,
    adversary_loss_weight=0.1,
)
debiased.fit(ds_train)
pred = debiased.predict(ds_test)
```

### Fairlearn (reductions)
```python
from fairlearn.reductions import ExponentiatedGradient, DemographicParity
from sklearn.linear_model import LogisticRegression

constraint = DemographicParity()
mitigator = ExponentiatedGradient(
    estimator=LogisticRegression(),
    constraints=constraint,
)
mitigator.fit(X, y, sensitive_features=A)
pred = mitigator.predict(X_test)
```

### Post-processing (equalized odds)
```python
from fairlearn.postprocessing import ThresholdOptimizer

postprocess = ThresholdOptimizer(
    estimator=base_model,
    constraints='equalized_odds',
    prefit=True,
)
postprocess.fit(X, y, sensitive_features=A)
# 매 group 별 threshold 의 different.
```

### Audit (Aequitas / Fairlearn)
```python
from fairlearn.metrics import MetricFrame, demographic_parity_difference, equalized_odds_difference
from sklearn.metrics import accuracy_score

mf = MetricFrame(
    metrics={'accuracy': accuracy_score,
             'selection_rate': lambda y, yp: yp.mean()},
    y_true=y_test,
    y_pred=pred,
    sensitive_features=A_test,
)
print(mf.by_group)
print('DP diff:', demographic_parity_difference(y_test, pred, sensitive_features=A_test))
print('EO diff:', equalized_odds_difference(y_test, pred, sensitive_features=A_test))
```

### Counterfactual check
```python
def counterfactual_fair(model, x, protected_attr_idx):
    flipped = x.copy()
    flipped[protected_attr_idx] = 1 - flipped[protected_attr_idx]
    return model.predict(x) == model.predict(flipped)

unfair_count = sum(not counterfactual_fair(model, x, idx) for x in X_test)
print(f'{unfair_count}/{len(X_test)} 의 prediction 의 protected attr 의 dependent')
```

## 🤔 결정 기준
| 상황 | Approach |
|---|---|
| Hiring / lending | Equalized opportunity (TPR) |
| Allocation (limited) | Demographic parity |
| Risk score | Calibration |
| Face recognition | Group fairness across skin tone |
| Healthcare | Equal opportunity + clinical |
| Recommendation | Counterfactual + diversity |

**기본값**: 매 audit 먼저. 매 metric 의 stakeholder 의 align. 매 reductions (Fairlearn) 의 baseline.

## 🔗 Graph
- 부모: [[Algorithmic-Fairness]]
- 변형: [[Demographic-Parity]] · [[Equalized-Odds]]
- 응용: [[AIF360]]
- Adjacent: [[EU-AI-Act]]

## 🤖 LLM 활용
**언제**: 매 high-stakes ML (hiring, lending, criminal justice). 매 fairness audit. 매 protected attribute 가 있는 production model.
**언제 X**: 매 group X 의 small data. 매 protected attr 의 정의 의 ambiguous.

## ❌ 안티패턴
- **Drop protected attribute**: 매 proxy 의 leak (zip code → race).
- **Single metric**: 매 다른 metric 의 violate.
- **No audit**: 매 silent discrimination.
- **Accuracy only**: 매 fairness 의 무시.
- **Post-processing only**: 매 root cause X.
- **One-shot fix**: 매 distribution shift → 매 re-bias.

## 🧪 검증 / 중복
- Verified (AIF360 docs, Fairlearn, Kleinberg paper).
- 신뢰도 A.
- Related: [[Algorithmic-Fairness]] · [[Algorithmic-Bias]] · [[AI-Governance]] · [[EU-AI-Act]].

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — metric + 3 stage + AIF360 / Fairlearn code + landmark case |
