Skip to content

Commit ac044f9

Browse files
cauchyturingclaude
andcommitted
fix: align copilot.py inference with server.py — MetaLearner S/T/X/DA + TS warning
- Replace hardcoded "t"/"x" MetaLearner selection with data-driven get_default_estimation_config() (considers sample size → S, treatment balance → DA, linearity → T/X) - Add time-series warning in estimate_effect when TS structure detected Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3a06e99 commit ac044f9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

causal_copilot/copilot.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ def estimate_effect(
626626
Updated CausalResult with populated effects dict.
627627
"""
628628
from causal_copilot.mcp.offline import (
629+
get_default_estimation_config,
629630
identify_confounders,
630631
prepare_treatment,
631632
select_estimation_method,
@@ -658,6 +659,14 @@ def estimate_effect(
658659
is_linear = bool(props.get("likely_linear", True))
659660
is_gaussian = bool(props.get("likely_gaussian", True))
660661

662+
# Time-series warning: causal effect estimation assumes i.i.d. samples
663+
if props.get("is_time_series", False):
664+
warnings_list.append(
665+
"Time-series structure detected — causal effect estimation "
666+
"assumes i.i.d. samples. Results may be biased if temporal "
667+
"lag structure matters. Consider time-series-specific methods."
668+
)
669+
661670
# --- Treatment type dispatch (4 cases, matching original) ---
662671
_, T0, T1, treatment_kind = prepare_treatment(
663672
df,
@@ -817,8 +826,14 @@ def estimate_effect(
817826
)
818827
elif selected_method == "metalearner":
819828
X_col = [c for c in names if c != treatment and c != outcome]
820-
# Pick learner variant based on data (matches original)
821-
learner = "t" if is_linear else "x"
829+
# Data-driven learner selection (S/T/X/DA based on balance + linearity)
830+
ml_config = get_default_estimation_config(
831+
"metalearner",
832+
df,
833+
treatment,
834+
is_linear=is_linear,
835+
)
836+
learner = ml_config.get("learner", "t")
822837
estimates = estimate_metalearner(
823838
df,
824839
treatment,

0 commit comments

Comments
 (0)