Apport marginal des familles amont : apparie, placebo et IC diagnostiques
Aucune famille ne survit : Brier et PR-AUC degrades sur les endpoints pre-declares, placebo par blocs ou par decalage souvent meilleur que la vraie serie. Les seuils dIC exposent desormais n_blocks_total, n_blocks_with_signal et n_effective_signals, avec refus de toute significativite sur un intervalle non exploitable.
This commit is contained in:
@@ -5,7 +5,13 @@ import pytest
|
||||
|
||||
import upstream_features as up
|
||||
from enrich_campaign import fit_logistic, predict_logistic, quantile_thresholds, verdict
|
||||
from risk_report import MIN_USABLE_BLOCKS, bootstrap_ci, paired_block_bootstrap
|
||||
from risk_report import MIN_USABLE_BLOCKS, bootstrap_ci, paired_block_bootstrap, pr_auc
|
||||
|
||||
|
||||
def _target(hit, terminal=1.0, amplitude=3.0, delay=3):
|
||||
return dict(events={"up_3": dict(hit=hit, terminal=terminal, amplitude=amplitude, delay=delay)},
|
||||
available_at="2026-01-01", panel=10, future_min_delta=0.0, future_max_delta=3.0)
|
||||
|
||||
|
||||
|
||||
def make_db(tmp_path):
|
||||
@@ -61,13 +67,27 @@ def test_external_features_never_change_when_a_future_value_changes(tmp_path):
|
||||
assert after[day][0] == snapshots[day], "une valeur plus récente ne réécrit pas le passé"
|
||||
|
||||
|
||||
def test_placebo_keeps_the_distribution_and_breaks_the_order(tmp_path):
|
||||
rows = [(index, index * 2.0) for index in range(200)]
|
||||
def test_placebo_reassigns_features_instead_of_reordering_rows():
|
||||
rows = [(f"j{index}", [index * 2.0]) for index in range(200)]
|
||||
shuffled = up.permute_blocks(rows, block=30, seed=5)
|
||||
assert sorted(shuffled) == sorted(rows), "la distribution marginale est conservée"
|
||||
assert shuffled != rows, "l'ordre temporel est bien cassé"
|
||||
assert [row for row, _ in shuffled] == [row for row, _ in rows], "l'ordre des journées est conservé"
|
||||
assert sorted(value for _, values in shuffled for value in values) == \
|
||||
sorted(value for _, values in rows for value in values), "distribution marginale conservée"
|
||||
assert [values for _, values in shuffled] != [values for _, values in rows], \
|
||||
"les features sont bien réassignées à d'autres journées"
|
||||
shifted = up.shift_rows(rows, shift=90)
|
||||
assert shifted[-1] == rows[89], "décalage temporel non causal explicite"
|
||||
assert [row for row, _ in shifted] == [row for row, _ in rows]
|
||||
assert shifted[0][1] == [rows[90][1][0]], "information d'une journée plus tardive"
|
||||
|
||||
|
||||
def test_pr_auc_is_cumulative_and_not_inflated():
|
||||
predictions = [dict(score={"up_3": score}, target=_target(hit))
|
||||
for score, hit in ((0.4, True), (0.3, False), (0.2, False), (0.1, True))]
|
||||
assert pr_auc(predictions, "up_3") == pytest.approx(0.75), \
|
||||
"AP = (1/1 + 2/4)/2 : la précision doit être cumulative"
|
||||
perfect = [dict(score={"up_3": score}, target=_target(hit))
|
||||
for score, hit in ((0.9, True), (0.8, True), (0.1, False))]
|
||||
assert pr_auc(perfect, "up_3") == pytest.approx(1.0)
|
||||
|
||||
|
||||
def test_paired_bootstrap_detects_a_systematic_difference():
|
||||
|
||||
Reference in New Issue
Block a user