|
1 | | -"""Kaggle / applied ML expert.""" |
2 | | - |
3 | | -from __future__ import annotations |
4 | | - |
5 | | -from typing import Any, Dict, List |
6 | | - |
7 | | -from epistemic_forge.models import ProjectSpec |
8 | | - |
9 | | - |
10 | | -def build_competition_kit( |
11 | | - spec: ProjectSpec, claims_bundle: Dict[str, Any], skills: List[str] |
12 | | -) -> Dict[str, Any]: |
13 | | - notebook_md = f"""# {spec.title} — Kaggle Spine |
14 | | -
|
15 | | -## Problem |
16 | | -{spec.question} |
17 | | -
|
18 | | -## Skills retrieved |
19 | | -{', '.join(skills) or 'none'} |
20 | | -
|
21 | | -## Plan |
22 | | -1. **Define target & metric** — match leaderboard metric exactly. |
23 | | -2. **Leakage audit** — time, group, target leakage checks. |
24 | | -3. **EDA** — missingness, cardinality, target balance, simple slices. |
25 | | -4. **Baseline** — linear/GBDT simple pipeline; record CV mean±std. |
26 | | -5. **Error analysis** — where does baseline fail? |
27 | | -6. **One improvement** — single ablated idea; measure lift. |
28 | | -7. **Ship** — reproducible seeds, requirements, README. |
29 | | -
|
30 | | -## Skeleton code |
31 | | -```python |
32 | | -import numpy as np |
33 | | -import pandas as pd |
34 | | -from sklearn.model_selection import StratifiedKFold, cross_val_score |
35 | | -from sklearn.pipeline import Pipeline |
36 | | -from sklearn.compose import ColumnTransformer |
37 | | -from sklearn.preprocessing import OneHotEncoder |
38 | | -from sklearn.impute import SimpleImputer |
39 | | -from sklearn.ensemble import HistGradientBoostingClassifier |
40 | | -
|
41 | | -# df = pd.read_csv('train.csv') |
42 | | -# y = df['target'] |
43 | | -# X = df.drop(columns=['target']) |
44 | | -
|
45 | | -# num_cols = X.select_dtypes(include='number').columns |
46 | | -# cat_cols = X.select_dtypes(exclude='number').columns |
47 | | -# pre = ColumnTransformer([ |
48 | | -# ('num', SimpleImputer(strategy='median'), num_cols), |
49 | | -# ('cat', Pipeline([ |
50 | | -# ('imp', SimpleImputer(strategy='most_frequent')), |
51 | | -# ('oh', OneHotEncoder(handle_unknown='ignore')), |
52 | | -# ]), cat_cols), |
53 | | -# ]) |
54 | | -# clf = Pipeline([('pre', pre), ('model', HistGradientBoostingClassifier(random_state=42))]) |
55 | | -# cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42) |
56 | | -# scores = cross_val_score(clf, X, y, cv=cv, scoring='roc_auc') |
57 | | -# print(scores.mean(), scores.std()) |
58 | | -``` |
59 | | -
|
60 | | -## Honest claims checklist |
61 | | -- [ ] Metric matches competition |
62 | | -- [ ] Split policy documented |
63 | | -- [ ] No target leakage features |
64 | | -- [ ] Baseline before complexity |
65 | | -""" |
| 1 | +"""L2 Epistemic Synthesis Engine: Leakage & Rigor Sentinel.""" |
| 2 | +from epistemic_forge.models import ProjectSpec, RigorSentinelOutput |
| 3 | +from epistemic_forge.llm import generate_structured |
| 4 | +from typing import Dict, Any |
| 5 | + |
| 6 | +def build_competition_kit(spec: ProjectSpec, claims_bundle: Dict[str, Any], skills: list) -> Dict[str, Any]: |
| 7 | + """Audit the premise for epistemic blind spots and target leakage.""" |
| 8 | + |
| 9 | + messages = [ |
| 10 | + {"role": "system", "content": "You are a Grandmaster ML Auditor. Your job is to look at a proposed research or data problem and identify 'target leakage'—where the answer is implicitly baked into the question—and propose strict falsification metrics."}, |
| 11 | + {"role": "user", "content": f"Problem Statement: {spec.question}\nKeywords: {spec.keywords}\nFind the blind spots and establish a robust baseline."} |
| 12 | + ] |
| 13 | + |
| 14 | + # Neuro-Symbolic Call |
| 15 | + result: RigorSentinelOutput = generate_structured( |
| 16 | + messages=messages, |
| 17 | + response_model=RigorSentinelOutput, |
| 18 | + model="gpt-4o-mini" |
| 19 | + ) |
| 20 | + |
66 | 21 | return { |
67 | | - "checklist": [ |
68 | | - "metric alignment", |
69 | | - "leakage audit", |
70 | | - "baseline CV", |
71 | | - "error analysis", |
72 | | - "single ablation", |
73 | | - ], |
74 | | - "notebook_markdown": notebook_md, |
| 22 | + "checklist": result.epistemic_blind_spots, |
| 23 | + "metric_alignment": result.falsification_metric, |
| 24 | + "baseline_architecture": result.robust_baseline, |
75 | 25 | "experiment_log_template": { |
76 | | - "run_id": "baseline_001", |
77 | | - "model": "HGB", |
78 | | - "cv_mean": None, |
79 | | - "cv_std": None, |
80 | | - "notes": "", |
81 | | - }, |
| 26 | + "status": "Audited by Rigor Sentinel", |
| 27 | + "notes": "Ensure no data from the future is used." |
| 28 | + } |
82 | 29 | } |
0 commit comments