if __name__ == "__main__":
    rng = np.random.default_rng(0)
    n = 2000

    # simulate two groups with different true base rates, and a
    # classifier with a threshold that is miscalibrated for one
    # group -- a common, realistic pattern when a model is
    # trained mostly on data from the majority group.
    group = rng.choice(["A", "B"], size=n, p=[0.7, 0.3])
    true_prob = np.where(group == "A", 0.3, 0.5)
    y_true = (rng.random(n) < true_prob).astype(int)

    score = y_true + rng.normal(0, 0.4, n)
    # group B's threshold is effectively stricter due to a
    # systematic score offset -- simulating a biased model
    score_adjusted = np.where(group == "B", score - 0.3, score)
    y_pred = (score_adjusted > 0.5).astype(int)

    print("=== Fairness audit ===")
    fairness_audit(y_true, y_pred, group)

    print("\n=== Overall accuracy ===")
    print(f"Accuracy: {(y_true == y_pred).mean():.3f}")
